computational-geometry

Perpendicular on a line from a given point

独自空忆成欢 提交于 2019-11-27 06:30:15
How can I draw a perpendicular on a line segment from a given point? My line segment is defined as (x1, y1), (x2, y2), If I draw a perpendicular from a point (x3,y3) and it meets to line on point (x4,y4). I want to find out this (x4,y4). I solved the equations for you: k = ((y2-y1) * (x3-x1) - (x2-x1) * (y3-y1)) / ((y2-y1)^2 + (x2-x1)^2) x4 = x3 - k * (y2-y1) y4 = y3 + k * (x2-x1) Where ^2 means squared From wiki : In algebra, for any linear equation y=mx + b, the perpendiculars will all have a slope of (-1/m), the opposite reciprocal of the original slope. It is helpful to memorize the slogan

Find if a point is inside a convex hull for a set of points without computing the hull itself

与世无争的帅哥 提交于 2019-11-27 06:16:24
What is the simplest way to test if a point P is inside a convex hull formed by a set of points X? I'd like an algorithm that works in a high-dimensional space (say, up to 40 dimensions) that doesn't explicitly compute the convex hull itself. Any ideas? The problem can be solved by finding a feasible point of a Linear Program. If you're interested in the full details, as opposed to just plugging an LP into an existing solver, I'd recommend reading Chapter 11.4 in Boyd and Vandenberghe's excellent book on convex optimization . Set A = (X[1] X[2] ... X[n]) , that is, the first column is v1 , the

How to efficiently find k-nearest neighbours in high-dimensional data?

梦想与她 提交于 2019-11-27 05:43:13
问题 So I have about 16,000 75-dimensional data points, and for each point I want to find its k nearest neighbours (using euclidean distance, currently k=2 if this makes it easiser) My first thought was to use a kd-tree for this, but as it turns out they become rather inefficient as the number of dimension grows. In my sample implementation, its only slightly faster than exhaustive search. My next idea would be using PCA (Principal Component Analysis) to reduce the number of dimensions, but I was

Location of highest density on a sphere

孤者浪人 提交于 2019-11-27 05:21:35
I have a lot of points on the surface of the sphere. How can I calculate the area/spot of the sphere that has the largest point density? I need this to be done very fast. If this was a square for example I guess I could create a grid and then let the points vote which part of the grid is the best. I have tried with transforming the points to spherical coordinates and then do a grid, both this did not work well since points around north pole are close on the sphere but distant after the transform. Thanks To add some other, alternative schemes to the mix: it's possible to define a number of

Shortest distance between points algorithm

烂漫一生 提交于 2019-11-27 03:46:11
Given a set of points on a plane, find the shortest line segment formed by any two of these points. How can I do that? The trivial way is obviously to calculate each distance, but I need another algorithm to compare. http://en.wikipedia.org/wiki/Closest_pair_of_points The problem can be solved in O(n log n) time using the recursive divide and conquer approach, e.g., as follows: Sort points along the x-coordinate Split the set of points into two equal-sized subsets by a vertical line x = xmid Solve the problem recursively in the left and right subsets. This will give the left-side and right

Sub O(n^2) algorithm for counting nested intervals?

筅森魡賤 提交于 2019-11-27 03:29:47
问题 We have a list of intervals of the form [a i , b i ] . For each interval, we want to count the number of other intervals that are nested within it. For example, if we had two intervals, A = [1,4] and B = [2,3] . Then the count for B would be 0 as there are no nested intervals for B ; and the count for A would be 1 as B fits within A . My question is, does there exist a sub- O(n 2 ) algorithm for this problem where n is the number of intervals? EDIT: Here are the conditions the intervals meet.

How can I detect the maximum-sized rectangle that I can draw onto the mask?

不羁的心 提交于 2019-11-27 03:27:28
问题 I'm making an image processing project and I have stuck in one the project's steps. Here is the situation; This is my mask: and I want to detect the maximum-sized rectangle that can fit into this mask like this. I'm using MATLAB for my project. Do you know any fast way to accomplish this aim. Any code sample, approach or technique would be great. EDIT 1 : The two algorithms below are works with lot's of the cases. But both of them give wrong results in some difficult cases. I'am using both of

What is the most efficient algorithm to find a straight line that goes through most points?

我的未来我决定 提交于 2019-11-27 02:58:14
The problem: N points are given on a 2-dimensional plane. What is the maximum number of points on the same straight line? The problem has O(N 2 ) solution: go through each point and find the number of points which have the same dx / dy with relation to the current point. Store dx / dy relations in a hash map for efficiency. Is there a better solution to this problem than O(N 2 )? jonderry There is likely no solution to this problem that is significantly better than O(n^2) in a standard model of computation. The problem of finding three collinear points reduces to the problem of finding the

How to check if line segment intersects a rectangle?

浪尽此生 提交于 2019-11-27 01:41:46
If you have 2 points, (x1, y1) and (x2, y2), which represent two opposite corners of a rectangle, and 2 other points, (x3,y3) and (x4,y4), which represent 2 endpoints of a line segment, how can you check if the line segment intersects the rectangle? (The line segment is just the segment contained between the given endpoints. It is not an infinite length line defined by those two points.) templatetypedef One very simple option would be to use a standard algorithm for checking whether two line segments intersect to check whether the line segments intersects any of the four line segments that

Area of rectangle-rectangle intersection

做~自己de王妃 提交于 2019-11-27 01:34:46
Below are 2 rectangles . Given the coordinates of the rectangle vertices - (x1, y1)...(x8, y8), how can the area of the overlapping region (white in the figure below) be caclulated? Note that: Coordinates of points might be any Rectangles may or may not overlap Assume area is 0 when rectangles don't overlap, or they overlap at point or line. If one rectangle is inside the other, then calculate area of smaller rectangle. Since you stated that the rectangles may not be aligned, possible answers may be nothing, a point, a line segment, or a polygon with 3-8 sides. The usual way to do this 2d