computational-geometry

How to find and print intersections of n given circles in O(n*log(n)) time?

心不动则不痛 提交于 2020-12-29 06:45:06
问题 I'm looking for an O(n*logn) algorithm to find and print the intersections of n given circles. Each circle is specified by its center and radius. An O(n 2 ) algorithm consists in checking if the distance between the centers is less than or equal to the sum of the radii (of the two circles being compared). However, I'm looking for a faster one! A similar problem is intersection of line segments. I think even my problem can be solved using line sweep algorithm, but I am unable to figure out how

Efficient way to find overlapping of N rectangles

半城伤御伤魂 提交于 2020-12-28 07:28:52
问题 I am trying to find an efficient solution for finding overlapping of n rectangles where rectangles are stored in two separate lists. We are looking for all rectangles in listA that overlap with rectangles in listB (and vice versa). Comparing one element from the first list to second list could take immensely large amount of time. I am looking for an efficient solution. I have two list of rectangles rect = Rectangle(10, 12, 56, 15) rect2 = Rectangle(0, 0,1, 15) rect3 = Rectangle (10, 12, 56,

How to get the intersection point? Ray Triangle Intersection C++

痞子三分冷 提交于 2020-07-24 02:06:58
问题 I would like to get the intersection point on a triangle when a ray go through it. I followed the on line tutorial and made a function, but I could not get the correct coordinates of intersection point. For example, I should get the intersection point (0, 3, -1), if I use ray origin (0, 2, -1), ray direction (0, 1, 0), triangle vertices p0 (0, 3, 0), p1 (-0.5, 3, -1), p2 (0.5, 3, -1). However, I have got the intersection point (0, 7, -1), which was not correct. I appreciate your time and help

How to get the intersection point? Ray Triangle Intersection C++

旧时模样 提交于 2020-07-24 02:02:47
问题 I would like to get the intersection point on a triangle when a ray go through it. I followed the on line tutorial and made a function, but I could not get the correct coordinates of intersection point. For example, I should get the intersection point (0, 3, -1), if I use ray origin (0, 2, -1), ray direction (0, 1, 0), triangle vertices p0 (0, 3, 0), p1 (-0.5, 3, -1), p2 (0.5, 3, -1). However, I have got the intersection point (0, 7, -1), which was not correct. I appreciate your time and help

How to get the intersection point? Ray Triangle Intersection C++

最后都变了- 提交于 2020-07-24 02:01:45
问题 I would like to get the intersection point on a triangle when a ray go through it. I followed the on line tutorial and made a function, but I could not get the correct coordinates of intersection point. For example, I should get the intersection point (0, 3, -1), if I use ray origin (0, 2, -1), ray direction (0, 1, 0), triangle vertices p0 (0, 3, 0), p1 (-0.5, 3, -1), p2 (0.5, 3, -1). However, I have got the intersection point (0, 7, -1), which was not correct. I appreciate your time and help

Distance between two polylines

吃可爱长大的小学妹 提交于 2020-07-16 16:52:48
问题 I want to calculate the distance d between two polylines: Obviously I could check the distance for all pairs of line-segments and choose the smallest distance, but this ways the algorithmn would have a runtime of O(n 2 ) . Is there any better approach? 回答1: Divide and conquer: Define a data structure representing a pair of polylines and the minimun distance between their axis-aligned minimum bounding boxes (AAMBB): pair = (poly_a, poly_b, d_ab) ) Create an empty queue for pair data

Faster way to calculate hexagon grid coordinates

隐身守侯 提交于 2020-06-25 21:21:09
问题 I'm using the following procedure to calculate hexagonal polygon coordinates of a given radius for a square grid of a given extent (lower left --> upper right): def calc_polygons(startx, starty, endx, endy, radius): sl = (2 * radius) * math.tan(math.pi / 6) # calculate coordinates of the hexagon points p = sl * 0.5 b = sl * math.cos(math.radians(30)) w = b * 2 h = 2 * sl origx = startx origy = starty # offsets for moving along and up rows xoffset = b yoffset = 3 * p polygons = [] row = 1

How to get uniformly distributed points in convex hull?

流过昼夜 提交于 2020-06-13 00:10:20
问题 Given a set of points, points = np.random.randn(...) # n 3d points I would like to uniformly fill the volume defined by the convex hull in which they lie by a list (np.array of shape nx3 ) of 3d points. I can get the convex hull by hull = scipy.spatial.ConvexHull(points) What would be the fastest way to get a list of points that uniformly fills this hull's volume? 回答1: 1) Find delaunay simplices of the hull 2) randomly sample the simplices based on their area 3) for each simplex, find uniform