computational-geometry

Finding if Path2D self-intersects

帅比萌擦擦* 提交于 2019-12-03 11:59:18
I need to find if Path2D intersects itself. For now, I do it by simply extracting an array of lines from path, and finding if any of these intersect. But it has O(n^2) complexity, and so it is very slow. Is there a faster way to do it? You can do this faster using the sweep-line algorithm: http://en.wikipedia.org/wiki/Sweep_line_algorithm Pseudocode: Each line has a start point and an end point. Say that `start_x` <= `end_x` for all the lines. Create an empty bucket of lines. Sort all the points by their x coordinates, and then iterate through the sorted list. If the current point is a start

Determining ordering of vertices to form a quadrilateral

点点圈 提交于 2019-12-03 09:12:17
Suppose I have 4 vertices in 2D space. Does anything know of an efficient algorithm which will give me an ordering of the vertices which corresponds to a simple quadrilateral? That is, it will label the vertices 1, 2, 3, 4 so that if I follow 1-2, 2-3, 3-4 I will have traced a simple (i.e. non-intersecting) quadrilateral. Just providing the name of a standard algorithm which I can google would be fine. You may be interested in methods of convex hull computing, such as Graham scan . If your shape is convex, you can go in winding order around the barycentre of your points (i.e. the centre of

How to compute the union polygon of two (or more) rectangles

筅森魡賤 提交于 2019-12-03 09:06:47
For example we have two rectangles and they overlap. I want to get the exact range of the union of them. What is a good way to compute this? These are the two overlapping rectangles. Suppose the cords of vertices are all known: How can I compute the cords of the vertices of their union polygon? And what if I have more than two rectangles? There exists a Line Sweep Algorithm to calculate area of union of n rectangles. Refer the link for details of the algorithm. As said in article, there exist a boolean array implementation in O(N^2) time. Using the right data structure (balanced binary search

Local maxima in a point cloud

我怕爱的太早我们不能终老 提交于 2019-12-03 08:58:25
I have a point cloud C, where each point has an associated value. Lets say the points are in 2-d space, so each point can be represented with the triplet (x, y, v). I'd like to find the subset of points which are local maxima. That is, for some radius R, I would like to find the subset of points S in C such that for any point Pi (with value vi) in S, there is no point Pj in C within R distance of Pi whose value vj is greater that vi. I see how I could do this in O(N^2) time, but that seems wasteful. Is there an efficient way to do this? Side Notes: The source of this problem is that I'm trying

Determining and storing Voronoi Cell Adjacency

耗尽温柔 提交于 2019-12-03 08:45:06
I will be working with a set of thousands of points. I can implement or use existing implementations of Fortunes Algorithm to produce the Voronoi diagram of the points, but my application also requires me to know adjacency with respect to each Voronoi Cell. More specifically, for any Voronoi cell I need to know the cells that are adjacent to this. At this point I'm not to concerned with output or storage method as I can likely massage an implementation to work in my favor. Is anyone aware of an algorithm, or better yet aware of an implemented algorithm that can accomplish cell adjacency

Find the Closest intersection point in plan

梦想与她 提交于 2019-12-03 08:11:18
I was asked following question in interview recently: Let suppose you have, following grid on Cartesian coordinate system ( Quadrant I). o - x - x - x - o | | | | | x - x - x - o - x | | | | | x - o - o - x - x where, o => person at intersection and x => no person at intersection class Point { int x; int y; boolean hasPerson; } Point findNearestPointWhereAllPeopleCanMeet(Point[] people) { } Implement a routine where given a list of people location (points), find a location(point) such that is closest point to all given point. How would you solve this problem ? 1) Approach is k-d tree, but do

Compute the Centroid of a 3D Planar Polygon

扶醉桌前 提交于 2019-12-03 07:35:44
This is a similar question to this one here . Given a list of 3D coordinates that define the surface( Point3D1 , Point3D2 , Point3D3 , and so on), how to calculate the centroid of the surface? In 2D the computation is given by the following formula : What about the 3D analogue? If it's a planar surface, you can transform to a coordinate system local to the plane, calculate the centroid using the formulas you presented, and then transform back to get its coordinates in 3D space. Just use the equations that you have twice, but the second time swap in z for y . That is, calculate the centroids of

Convex hull in higher dimensions, finding the vertices of a polytope

扶醉桌前 提交于 2019-12-03 06:56:17
Suppose I have a point cloud given in 6-dimensional space, which I can make as dense as needed. These points turn out to lie on the surface of a lower-dimensional polytope (i.e. the point vectors (x1, x2, ... x6) appear to be coplanar). I would like to find the vertices of this unknown polytope and my current attempt makes use of the qhull algorithm, via the scipy interface in Python. In the beginning I would only get error messages, apparently caused by the lower dimensional input and/or the many degenerate points. I have tried a couple of brute-force methods to eliminate the degenerate

C++ 2D tessellation library?

。_饼干妹妹 提交于 2019-12-03 06:27:00
I've got some convex polygons stored as an STL vector of points (more or less). I want to tessellate them really quickly, preferably into fairly evenly sized pieces, and with no "slivers". I'm going to use it to explode some objects into little pieces. Does anyone know of a nice library to tessellate polygons (partition them into a mesh of smaller convex polygons or triangles)? I've looked at a few I've found online already, but I can't even get them to compile. These academic type don't give much regard for ease of use. balint.miklos CGAL has packages to solve this problem. The best would be

How to find a random point in a quadrangle?

爷,独闯天下 提交于 2019-12-03 06:10:45
I have to be able to set a random location for a waypoint for a flight sim. The maths challenge is straightforward: "To find a single random location within a quadrangle, where there's an equal chance of the point being at any location." Visually like this: An example ABCD quadrangle is: A:[21417.78 37105.97] B:[38197.32 24009.74] C:[1364.19 2455.54] D:[1227.77 37378.81] Thanks in advance for any help you can provide. :-) EDIT Thanks all for your replies. I'll be taking a look at this at the weekend and will award the accepted answer then. BTW I should have mentioned that the quadrangle can be