computational-geometry

Java library for creating straight skeleton?

坚强是说给别人听的谎言 提交于 2019-12-04 05:37:54
I have as an input a 2D polygon with holes, and I need to find it's straight skeleton, like in the picture: (source: cgal.org ) Maybe there is a good Java library for it? And if not, can you point me to the good explanation of the algorithm, so I could implement it myself? (I haven't found good resources on Google) I wrote this a little while back. Not sure if it's robust enough. https://github.com/twak/campskeleton (edited for 2018...) See http://www.sable.mcgill.ca/~dbelan2/roofs/roofs.html which contains an applet. Edit: Ah. I see that " Straight Skeleton " is a technical term. The

A linear-time algorithm to find any vertex of a polygon visible from other vertex

柔情痞子 提交于 2019-12-04 05:34:41
Suppose there is a polygon with no holes and self-intersections (i.e. a simple polygon) defined by n vertices. Choose a reflex vertex v of this polygon. I'd like to find any other vertex u of the same polygon which is "visible" from the vertex v . By visible I mean, that a line segment between v and u lies completely inside the polygon. Is there an algorithm to do that in O(N) time or better? Is there an algorithm that can find all visible vertices in O(N) time? A quick research suggests that for a given polygon and any point inside this polygon a visibility polygon can be constructed in O(N)

How do I find the overlapping area between two arbitrary polygons

半世苍凉 提交于 2019-12-04 05:19:39
I'm trying to create a method that will take in two arbitrary lists of nodes, for a subject and a clipping polygon, and output either: a) the area of the overlap b) a list of nodes for the resulting (clipped) polygon so that I can calculate the area I've found lots of examples which clip an arbitrary polygon using a rectangular window (which is fairly standard in graphics) but that's not what I need. I understand that it's fairly complex, particularly when you get holes, convex polygons and the like. The only simplifying assumption which I can make is that the arbitrary polygons will not

Python : Ramer-Douglas-Peucker (RDP) algorithm with number of points instead of epsilon

若如初见. 提交于 2019-12-04 04:42:50
I would like to modify this following python script for RDP algorithm with the purpose of not using epsilon but to choose the number of points I want to keep at the final : class DPAlgorithm(): def distance(self, a, b): return sqrt((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2) def point_line_distance(self, point, start, end): if (start == end): return self.distance(point, start) else: n = abs( (end[0] - start[0]) * (start[1] - point[1]) - (start[0] - point[0]) * (end[1] - start[1]) ) d = sqrt( (end[0] - start[0]) ** 2 + (end[1] - start[1]) ** 2 ) return n / d def rdp(self, points, epsilon): """

Algorithm to find all convex quadrilaterals from the given list of 2d points

我与影子孤独终老i 提交于 2019-12-04 04:20:25
I have to make a program to find all convex quadrilaterals from the given list of 2d points. I have tried it with vector cross product but it doesn't seem to be a correct solution. Maybe there is some effective algorithm to this problem but I can not find it. This is an example case with inputs and outputs: Input Number of Points: 6 coordinates of points (x,y): 0 0 0 1 1 0 1 1 2 0 2 1 Output Number of convex quadrilaterals: 9 Gareth Rees A quadrilateral is convex if its diagonals intersect. Conversely, if two line segments intersect, then their four endpoints make a convex quadrilateral. Every

Minimize sum of distances in point pairs

自闭症网瘾萝莉.ら 提交于 2019-12-04 04:18:33
I have a bunch of points on a 2-dimensional Grid. I want to group the Points into pairs, while minimizing the sum of the euclidean distances between the points of the pairs. Example: Given the points: p1: (1,1) p2: (5,5) p3: (1,3) p4: (6,6) Best solution: pair1 = (p1,p3), distance = 2 pair2 = (p2,p4), distance = 1 Minimized total distance: 1+2 = 3 I suspect this problem might be solvable with a variant of the Hungarian Algorithm ?! What is the fastest way to solve the problem? (Little Remark: I always should have less than 12 points.) ChuckCottrill The problem you are trying to solve is

Extending a line segment to fit into a bounding box

假如想象 提交于 2019-12-04 03:21:40
问题 I have a line segment defined by two pointF s, along with a 2D bounding rectangle. I want to extend the line segment as much as possible in both directions so that the segment is flush with the walls of the bounding box. Here are some examples of what I'm trying to do: Does anyone have any suggestions on how to do this? 回答1: Here is an code example in python: def extend(xmin, ymin, xmax, ymax, x1, y1, x2, y2): if y1 == y2: return (xmin, y1, xmax, y1) if x1 == x2: return (x1, ymin, x1, ymax) #

Generating outside supporters into mesh for 3D printing

我是研究僧i 提交于 2019-12-04 02:20:18
问题 Prologue This is my attempt to re-ask the closed Generating supporters for 3D printing as it is interesting question but lacking important details ... This is intended as Q&A and currently I am working on the code for the answer but feel free to answer (I accept the best answer). Problem description OK here some basic info about the problem: Supports in 3D Printing: A technology overview As this is a huge problem I will focus on the generic mesh/support-pattern merging geometry problem. In a

Check if a point projected on a line segment is not outside it

只谈情不闲聊 提交于 2019-12-04 00:40:35
问题 See the image above; basically, I want a simple test to check if a point is within the line segment's range. The information (or input, if you prefer) I have is the point's coordinates, and the line segment termination points' coordinates. The output I want is a simple boolean. How can I check this in a simple way? 回答1: You can have a simple and uniform check if you use the inner product. The inner product between two vectors can be geometrically visualised as the product of the lengths of

What is most efficient way to find the intersection of a line and a circle in python?

こ雲淡風輕ζ 提交于 2019-12-03 23:37:48
问题 I have a polygon consists of lots of points. I want to find the intersection of the polygon and a circle. Providing the circle center of [x0,y0] and radius of r0, I have wrote a rough function to simply solve the quadratic equation of the circle and a line. But what about the efficiency of find the intersection of every line segment of the polygon one by one? Is there more efficient way? I know sympy already provide the feature to get the intersections of different geometry. But also what