computational-geometry

Compute the area of intersection between a circle and a triangle?

风格不统一 提交于 2019-11-27 11:43:10
How does one compute the area of intersection between a triangle (specified as three (X,Y) pairs) and a circle (X,Y,R)? I've done some searching to no avail. This is for work, not school. :) It would look something like this in C#: struct { PointF vert[3]; } Triangle; struct { PointF center; float radius; } Circle; // returns the area of intersection, e.g.: // if the circle contains the triangle, return area of triangle // if the triangle contains the circle, return area of circle // if partial intersection, figure that out // if no intersection, return 0 double AreaOfIntersection(Triangle t,

Fill arbitrary 2D shape with given set of rectangles

和自甴很熟 提交于 2019-11-27 11:41:50
I have a set of rectangles and arbitrary shape in 2D space. The shape is not necessary a polygon (it may be a circle), and rectangles have different widths and heights. The task is to approximate the shape with rectangles as close as possible. I can't change rectangles dimensions, but rotation is permitted. It sounds very similar to packing problem and covering problem but covering area is not rectangular... I guess it's NP problem, and I'm pretty sure there should be some papers that show good heuristics to solve it, but I don't know what to google? Where should I start? Update: One idea just

Testing whether a polygon is simple or complex

≡放荡痞女 提交于 2019-11-27 11:33:13
问题 For a polygon defined as a sequence of (x,y) points, how can I detect whether it is complex or not? A complex polygon has intersections with itself, as shown: Is there a better solution than checking every pair which would have a time complexity of O(N 2 )? 回答1: There are sweep methods which can determine this much faster than a brute force approach. In addition, they can be used to break a non-simple polygon into multiple simple polygons. For details, see this article, in particular, this

How to know if a line intersects a plane in C#?

情到浓时终转凉″ 提交于 2019-11-27 11:31:56
问题 I have two points (a line segment) and a rectangle. I would like to know how to calculate if the line segment intersects the rectangle. 回答1: From my "Geometry" class: public struct Line { public static Line Empty; private PointF p1; private PointF p2; public Line(PointF p1, PointF p2) { this.p1 = p1; this.p2 = p2; } public PointF P1 { get { return p1; } set { p1 = value; } } public PointF P2 { get { return p2; } set { p2 = value; } } public float X1 { get { return p1.X; } set { p1.X = value;

determine if a given point is inside the polygon

…衆ロ難τιáo~ 提交于 2019-11-27 11:23:21
问题 Given a convex polygon as a counter-clockwise list of n vertices, give O(lgn) algorithm to determine if a given point is inside the polygon. Assume the basic operations take O(1). I am think a direction that: if a point is inside a convex polygon, what is the special relationship among the points and all the vertecies or edges? Also, I am guessing the trick here is the convex polygon which makes the algorithm lgn. 回答1: The only solution for this problem I know of requires O(n) polygon

FInd overlapping appointments in O(n) time?

时光怂恿深爱的人放手 提交于 2019-11-27 09:47:06
问题 I was recently asked this question in an interview. Even though I was able to come up the O ( n ²) solution, the interviewer was obsessed with an O ( n ) solution. I also checked few other solutions of O ( n log n ) which I understood, but O ( n ) solution is still not my cup of tea which assumes appointments sorted by start-time. Can anyone explain this? Problem Statement: You are given n appointments. Each appointment contains a start time and an end time. You have to retun all conflicting

Algorithm to compute a Voronoi diagram on a sphere?

亡梦爱人 提交于 2019-11-27 09:30:15
问题 I'm looking for a simple (if exists) algorithm to find the Voronoi diagram for a set of points on the surface of a sphere. Source code would be great. I'm a Delphi man (yes, I know...), but I eat C-code too. 回答1: Here's a paper on spherical Voronoi diagrams. Or if you grok Fortran (bleah!) there's this site. Original link (dead): https://people.sc.fsu.edu/~jburkardt/f_src/sxyz_voronoi/sxyz_voronoi.html 回答2: Update in July 2016: Thanks to a number of volunteers (especially Nikolai Nowaczyk and

Circular approximation of polygon (or its part)

一个人想着一个人 提交于 2019-11-27 08:17:45
问题 SHORT DESCRIPTION OF MY PROBLEM I need to implement GCODE autorefactoring from G1 instructions to G2 and G3 (http://www.cnccookbook.com/CCCNCGCodeArcsG02G03.htm) for 3D Printing. G1 is a movement in straight line with printing (path is describe by vector). I'm searching for algorytm to aproxymate circle/arc (specialy it's midpoint) based on given vectors path. Note that G2 and G3 can't print curves that are not part of a circle - so not every vectors path can be approximate this way. LONG

How to create a polygon out of the outer cells of a contiguous patch of cells

和自甴很熟 提交于 2019-11-27 07:23:47
问题 I have below a contiguous patch of cells plotted in Matlab. The outer cells of the red patch have to be determined and then a polygon joining the centers of these cells will give me a polygon. How do i compute the outer cells of the contiguous patch? I have an array of integers whose elements denote the cell in the red patch, for example, a=[1;64;23;456;345]; Each element , say 64 corresponds to a cell in the image, and it is the cell belonging to the red patch. The motivation to solve the

Angle between two vectors in R

白昼怎懂夜的黑 提交于 2019-11-27 06:49:17
What the most efficient way in the programming language R to calculate the angle between two vectors? According to page 5 of this PDF , sum(a*b) is the R command to find the dot product of vectors a and b , and sqrt(sum(a * a)) is the R command to find the norm of vector a , and acos(x) is the R command for the arc-cosine. It follows that the R code to calculate the angle between the two vectors is theta <- acos( sum(a*b) / ( sqrt(sum(a * a)) * sqrt(sum(b * b)) ) ) My answer consists of two parts. Part 1 is the math - to give clarity to all readers of the thread and to make the R code that