Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
A math problem I've been stuck on for a couple days.
Given a set of points on a 2D plane (more than 11), find the largest circle possible which will not enclose more than 11 points.
The obvious approach would be to take all possible subsets of size 12, then find the minimum enclosing circle for each, but that would take far too long to calculate.
any ideas on a more efficient method?
I suspect that there's a thoroughly impractical O(n log n)-time algorithm that computes the order-12 (!) Voronoi diagram and proceeds as in the O(n log n)-time algorithm for largest empty circle. Realistically, every viable circle is determined by three of the input points (on the boundary) or two (as the diameter). Naively trying all of them is quartic time, but for each pair of points P and Q, the points on one side of the line PQ are totally ordered with respect to which other points above the circle encloses, as are the points below. This insight gets us to n^3 log n, by sorting; quadratic should be possible using a selection algorithm.
For each point:
Compute the distance to every other point - O(n)
Run a selection algorithm to find the 12th closest point - O(n).
Let x = the distance between these two points.
Find the minimum x. Subtract the smallest possible value from that value, then you have your circle diameter.
Running time: O(n2).
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 6 years ago.
Improve this question
Is there any known algorithm to solve this ?
There's a related problem that's solvable with a greedy algorithm: given the points and a radius, find the minimum number of circles. This algorithm repeatedly places a circle whose left edge lies on the leftmost uncovered point, running in time O(n) on points sorted by x.
To get an algorithm for the requested problem, sort the points once and then use binary search to find the least radius that will result in at most d circles. Assuming that the x coordinates can be represented by machine words, this should be fine. (If not, there are other algorithms.)
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
The convex hull can be found by stretching a rubber band so that it contains all the points and then releasing it.
So my question is : lets assume that we have a robot (a theoretical robot) to solve this problem.
We give it the coordinates of our points ( we have n points ) .
It uses some pins to indicate the points in a board (O(n)).
Now we choose a point (it's not important which one we choose) then we check its distance with other points like ( sqr( x^2 + y^2 ) ) . And we find the Max distance .
Then the robot uses a rubber band and extends it in form of a circle with a radius of distance we found in step 2 and centered in the point we chose in step 2. And it releases the band .
Then the robot needs to follow the rubber band to find the vertices of the convex hull in O( m ) where m is the vertices that convex hull consists of them.(m <= n)
so the totall order of the algorithem (this way) would be O(n).
i know i did not take into account the time the rubber band needs to strech or the time it needs for the contraction.
but assuming we have lots of points it (contraction/streching) takes much less than O(n).
is there anyway to simulate the effect of the rubber band in computer?
i know the lowest possible order for convex hull is said to be O(nlg(n)) due to the sorting lower band .
I guess you could emulate that "rubber band algorithm" using some sort of optimization algorithms, but it will probably be horribly slow. Keep in mind that in a sense, the physical world is a gigantic, immensely complex computer, all the time figuring out complex stuff such as gravity, magnetic force, etc., and last but not collision-detection.
First, let's do the setup:
the rubber band is represented as a doubly-linked list of nodes holding the position of each "atom" in the rubber band (thinking of the rubber band as a 1-d chain of atoms)
the pins are represented by some sort of spatial map, or very fine-grained n-dimensional array holding the information of whether some small region contains a pin or not
Now, the actual algorithm:
whenever an "atom" in the rubber band touches/is very near to a pin (according to the spatial map, or n-d array) that atom is fixed and can no longer move
for all other atoms, slightly alter their positions in order to minimize the distances to their respective adjacent neighbours; you could do this with, e.g., a stochastic optimization or a swarm algorithms
repeat until all the atoms have "settled down"
Of course, the complexity of this algorithm is terrible, and far worse than O(n) or even O(nlogn), because all the expensive computation of the "rubber band" is usually performed be that great physics engine called the universe. (You could probably achieve a similar result by entering the "rubber band and board of pins" problem into any modern physics simulation.)
"is there anyway to simulate the effect of the rubber band in computer": no, not as regards computational complexity. A computer operation handles a constant number of operands at a time. For instance, typical convex hull algorithms take the points three by three and check whether they form a clockwise or counterclockwise triangle. This is said to be done in constant time.
Releasing the band involves all N points and cannot be implemented as a primitive operation.
If you try to somehow emulate it with a computer, you can be sure that it will take at least O(N Log(N)) operations. Anyway, in a discrete universe (integer coordinates), O(N) could be possible using radix sort.
but assuming we have lots of points it takes much less than O(n).
No it doesn't, because of this step:
Now we choose a point (it's not important which one we choose) then we check its distance with other points like ( sqr( x^2 + y^2 ) ) . And we find the Max distance .
You cannot find this max distance in less than O(n).
Also:
Then the robot uses a rubber band and extends it in form of a circle with a radius of distance we found in step 2 and centered in the point we chose in step 2. And it releases the band .
Then the robot needs to follow the rubber band to find the vertices of the convex hull in O( m ) where m is the vertices that convex hull consists of them.(m <= n)
This takes O(m*n) time, see the Jarvis march algorithm. You need to check that each point is actually part of the convex hull, you can't just extend the elastic band once and be done with it.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have N points in at 3D space (I think I can grasp myself general N-dimensional case) and approximate distances to these points, how can I compute my position relative to these N points?
EDIT
Please note that the distances are approximate, so the more approximate distances I have the more convenient result I should get
Thank you!
I would write down an equation that gives you some measure of the errors associated with a possible location, and then find the location that minimizes this measure. My first attempt would be to minimize the sum of the squares of the difference between the distance measured and the distance worked out from the possible location, for each of your approximate distance, so you are minimizing something like SUM_i((sqrt((X-Ai)^2 + (Y-Bi)^2 + (Z-Ci)^2) - Di)^2) where X,Y,Z is the location co-ordinates you are trying to find, (Ai,Bi,Ci) is the co-ordinates of one of the objects from which you are measuring distances, and Di is the distance measured. It doesn't look very pretty, but you should at least be able to compute derivatives and then find some sort of minimization routine in a math library.
You have distances from given N points in a 3D space and their approximate error values. So, you have a thick sphere for each of the points that you are in. You get all of them, calculate their intersection area, and take that area's center point as your approximate location.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Is there any method or algorithm to determine convex (or non-convexity) property of a region from outside (perimeter) ?
One way is plotting tangent line in each point of perimeter and discuss how many times this line intersect the perimeter points. If no intersect shown (for all points of perimeter ) we can conclude region is convex. In otherwise region is non-convex.
Second way is determine interior angel of each point of perimeter and discuss if it's bigger than 180 or not. The region is non-convex if at least one point in perimeter exist it's interior angel bigger than 180.
Are there another simpler ways?
Any ideas or solution would be appreciated, thanks.
One thing to observe when doing this is that as you traverse the sides of a convex polygon, all the turns will be to the same side. That is, if you are traversing around the vertices in a counter-clockwise direction, all of the turns will be to the left; if you are traversing around the vertices in a clockwise direction, all of the turns will be to the right. If you ever observe a turn to the opposite side of any others observed, then you know you're dealing with a non-convex polygon. If all of the turns are to one side, then it is a convex polygon.
So, all you need to do is take look three vertices at a time, call them vn, vn+1 and vn+2. You can then determine which side of the line segment connecting vn and vn+2 the vertex vn+1 sits on. For CCW, vn+1 should be on the right of the line segment, and for CW it should be on the left. There is an answer to another question which provides a method for determining this.
There are additional implementation details you should work out (like how to deal with n=N, the number of points in your polygon, but this should provide you with a place to start.
An implementation based on this approach will run in O(N) time and space.
UPDATE: In response to the question below, "how about non-polygonal regions"? In general this is much harder. Mathematically, a region can be shown to be non-convex by finding a line segment with endpoints in the interior of the region but which has some portion of the line segment exterior to the region. I suspect you're looking for a way of implementing this using a digital computer, and so the pure mathematical approach is not practical.
So, you're going to have to offer some sort of constraints as to the types regions before the problem becomes intractable. That is, you have to constrain your problem space so that things like Nyquist sampling of the perimeter of the boundary do not incorrectly identify a non-convex region as being convex.
Assuming you can properly constrain the problem, any solution you can come up with, which can be implemented on a digital computer will have to approximate the region. You can either generate a piece-wise linear approximation of the region in question and run the algorithm above, or pick the proper set of points along the boundary of the region and calculate their derivative. Each successive sample should rotate the angle of the tangent line by some increment in the same direction. But again, it gets downs to sampling.
If you have other information about the nature of any nonlinearities which comprise the boundary of your region, you may be able to symbolically demonstrate whether a segment of the boundary is convex. The problem then reduces to showing that it remains convex when joined to the adjacent sections, which again is going to be problem specific.
So, my suggestion is, for digital computer implementation, approximate as needed the boundary of the region by a polygon and run the method defined above on that approximation.
An algorithm I've used (in pseudo code):
function isConvex(vertices[Count] V):
convex = true
if Count <= 3 return convex
for N = 0 to Count while convex:
// line segment between previous and subsequent vertices
LineSegment segment1 = new LineSegment(
V[(N + Count - 1) % Count], V[(N + 1) % Count]);
// line segment between the point and any other point
LineSegment segment2 = new LineSegment((V[N], V[N+2 % Count]);
if not segment1.intersects(segment2) then convex = false;
return convex
I don't know if this is optimal or simpler than the algorithms you've already tried.
The LineSegment.intersects() method already existed making this really easy to write.
The actual code used segment2 from the previous iteration as segment 1 of the current iteration making it faster but more complex to write even in pseudo code.
And also, for what it's worth, the original of this algorithm was written in assembly language on a processor that no longer exists, so I won't be providing actual code ;-).
I was asked this question in Yahoo for machine learning profile. Given a set of points (x,y) coordinates I was asked to find points with lowest distance in O(n) or O(log n )time.
Obviously I was able to come up with O(n^2) time but was no way near getting the better algorithm. Even though the problem statement was screaming for Divide and Conquer I just could not come up with the reasoning for the merge step. I also googled for this question on the internet and found that It is actually very popular but I still could not get hold of the reasoning of the merge step.
Can anyone help me out with this?
Input: (x1,y1),(x2,y2),(x3,y3),(x4,y4),(x5,y5)
The problem can be solved in O(n log n) time using the recursive divide and conquer approach, e.g., as follows:
1.Sort points according to their x-coordinates.
2.Split the set of points into two equal-sized subsets by a vertical line x=xmid.
3.Solve the problem recursively in the left and right subsets. This yields the left-side and right-side minimum distances dLmin and dRmin, respectively.
4.Find the minimal distance dLRmin among the pair of points in which one point lies on the left of the dividing vertical and the second point lies to the right.
5.The final answer is the minimum among dLmin, dRmin, and dLRmin.
http://en.wikipedia.org/wiki/Closest_pair_of_points