computational-geometry

Asymptotically optimal algorithm to compute if a line intersects a convex polygon

筅森魡賤 提交于 2019-12-03 05:51:07
问题 An O(n) algorithm to detect if a line intersects a convex polygon consists in checking if any edge of the polygon intersects the line, and look if the number of intersections is odd or even. Is there an asymptotically faster algorithm, e.g. an O(log n) one? 回答1: lhf's answer is close to correct. Here is a version that should fix the problem with his. Let the polygon have vertices v0, v1, ..., vn in counterclockwise order. Let the points x0 and x1 be on the line. Note two things: First,

Compute the area covered by cards randomly put on a table

有些话、适合烂在心里 提交于 2019-12-03 05:21:44
This is an interview question, the interview has been done. Given a deck of rectangular cards, put them randomly on a rectangular table whose size is much larger than the total sum of cards' size. Some cards may overlap with each other randomly. Design an algorithm that can calculate the area the table covered by all cards and also analyze the time complexity of the algorithm. All coordinates of each vertex of all cards are known. The cards can overlap in any patterns. My idea: Sort the cards by its vertical coordinate descending order. Scan the cards vertically from top to bottom after

The minimum perimeter convex hull of a subset of a point set

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-03 05:12:31
Given n points on the plane. No 3 are collinear. Given the number k. Find the subset of k points, such that the convex hull of the k points has minimum perimeter out of any convex hull of a subset of k points. I can think of a naive method runs in O(n^k k log k). (Find the convex hull of every subset of size k and output the minimum). I think this is a NP problem, but I can't find anything suitable for reduction to. Anyone have ideas on this problem? An example, the set of n=4 points {(0,0), (0,1), (1,0), (2,2)} and k=3 Result: {(0,0),(0,1),(1,0)} Since this set contains 3 points the convex

Convex hull of (longitude, latitude)-points on the surface of a sphere

强颜欢笑 提交于 2019-12-03 05:00:32
问题 Standard convex hull algorithms will not work with (longitude, latitude)-points, because standard algorithms assume you want the hull of a set of Cartesian points. Latitude-longitude points are not Cartesian, because longitude "wraps around" at the anti-meridian (+/- 180 degrees). I.e., two degrees east of longitude 179 is -179. So if your set of points happens to straddle the anti-meridian, you will compute spurious hulls that stretch all the way around the world incorrectly. Any suggestions

Initializing Half-edge data structure from vertices

▼魔方 西西 提交于 2019-12-03 04:17:27
问题 I'm working on implementing various subdivision algorithms (such as catmull-clark); to do this efficiently requires a good way to store information about a grid of tesselated polygons. I implemented the half-edge data structure as outlined by flipcode, but now I'm not sure how to populate the data structure from vertices! My initial attempt was to create vertices group vertices into faces sort vertices within faces (using their angle relative to the centroid) for each face, grab the first

Triangle partitioning

此生再无相见时 提交于 2019-12-03 04:17:16
问题 This was a problem in the 2010 Pacific ACM-ICPC contest. The gist of it is trying to find a way to partition a set of points inside a triangle into three subtriangles such that each partition contains exactly a third of the points. Input: Coordinates of a bounding triangle: (v1x,v1y),(v2x,v2y),(v3x,v3y) A number 3n < 30000 representing the number of points lying inside the triangle Coordinates of the 3n points: (x_i,y_i) for i=1...3n Output: A point (sx,sy) that splits the triangle into 3

How to find first intersection of a ray with moving circles

╄→尐↘猪︶ㄣ 提交于 2019-12-03 03:39:23
I have been struggling with a problem for a while and so far have not found any solution better then the naive one: N circles are given that are moving according to a linear law. For each of the circles we have its initial (at moment 0.0) radius, initial coordinates and its radius and coordinates at moment 1.0 (end moment). We also have k rays given with coordinates of their origin and a vector along the ray. Each ray only exists at a given moment t k . I need to be able to find the first intersection of a ray with any of the circles. The expected number of k is quite large (millions or

Determining polygon intersection and containment

孤者浪人 提交于 2019-12-03 03:19:14
I have a set of simple (no holes, no self-intersections) polygons, and I need to check that they don't intersect each other (one can be entirely contained in another; that is okay). I can check this by simply checking the per-vertex inside-ness of one polygon versus other polygons. I also need to determine the containment tree, which is the set of relationships that say which polygon contains any given polygon. Since no polygon can intersect any other, then any contained polygon has a unique container; the "next-bigger" one. In other words, if A contains B contains C, then A is the parent of B

2D Geometry library: LGPL alternative to CGAL? [closed]

时光总嘲笑我的痴心妄想 提交于 2019-12-03 01:20:11
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . CGAL seems to do just about everything I need and a little more for my upcoming project. It can create polygons out of arc line segments and run boolean operations on them. It has spatial sorting packages already that would save me a lot of time regarding a few things and the whole library seems quite

How to find all the intersection points between two contour-set in an efficient way

百般思念 提交于 2019-12-03 00:37:00
I'm wondering about the best way to find all the intersection points (to roundoff error) between two sets of contour lines. Wich is the best method? Here is the example: import matplotlib.pyplot as plt import numpy as np x = np.linspace(-1,1,500) X,Y = np.meshgrid(x,x) Z1 = np.abs(np.sin(2*X**2+Y)) Z2 = np.abs(np.cos(2*Y**2+X**2)) plt.contour(Z1,colors='k') plt.contour(Z2,colors='r') plt.show() I want some similar to: intersection_points = intersect(contour1,contour2) print intersection_points [(x1,y1),...,(xn,yn)] import collections import matplotlib.pyplot as plt import numpy as np import