How to place n points in a plane so that the distance between every two points is unique and at the same time we could choose one of them that is the closest for all others n-1 points.
I tried to draw it. But I was able to draw it only for max n=5. I drew two perpendicular lines. One point I was intersection of the lines and the others points lie on the line so that they formed a quadrilateral and point I was inside. With more points it seems impossible to me but I can't prove why
Related
I have 5 {x,y} points randomly placed on a grid
Each of the points do not know the {x,y} coordinates of the other points
Each of the points do know the distance of each of the other points from their {x,y} position
Each of the points exchanges this distance information with every other point
So every point knows every distance of every other point
Using this distance information every point can calculate (by finding the angles) triangles for every other point using itself as a reference point
Example, point 1 can calculate the following triangles:
1-2-3,
1-2-4,
1-2-5,
1-3-4,
1-3-5,
1-4-5,
and using the distance data recieved from the other points it can also calculate
2-3-4,
2-3-5,
2-4-5,
3-4-5
I would like to build a map of the location of every other point relative to a single point
How should I go about doing this? I am asuming it would be some kind of triangulation algorithm but these mainly seem to compute the location of a point from three other points, not the other way around where the other points {x,y} coordinates are discovered based on only the distance information.
I have tried plotting the two possible triangles for every 3 triangle points and then rotating them on a fixed known point to try and align them, but I think this avenue will end up with too many possibilities and errors
Ultimately I would like every point to end up with {x,y} coordinates of every other point relative to itself
You know the distance from one point to every other, dij. Thus, point 2 lies in a circumference of center point 1 and radius = d12. Point 3 lies in a circumference of center point 1 and R=d13 and it also lies in another circumference of center point 2 and R=d23.
See this picture:
I've set point 2 in X-axis for simplicity.
As you see, point 3 is on the intersection of two cicrcumferences centered at P1 and P2. There is a second intersection, P3a. Let's choose the one that is upwards and continue.
For P4 we can use three circumferences, centered at P1, P2 and P3. Again we get two solutions.
The same process can be done with the rest of points. For Pn you have n-1 circumferences.
I'm sure you can find the maths for circle-circle intersection.
Some remarks must be observed:
1) The construction is simpler if you first sort the points by distance to P1.
2) Not all distances generate a solution. For example, increase d13 an there's no intersection between the two circumferences for P3. Or increase d14 and now the three circumferences don't intersect in just the two expected points 4 and 4a.
3) This fact can be overworked by considering the average of intersections and the distance from each solution to this average. You can set a tolerance in these distances and tell if the average is a solution or else some dij is wrong. Since two solutions are possible, you must consider two averages.
4) The two possible triangulations are symmetric, over X-axis in the case I've drawn.
The real solution is obtained by a rotation around P1. To calculate the angle of rotation you need the {x,y} coordinates of another point.
I have two problem first how to calculate the minimum distance between two lines.
For details I am attaching an image here.
In the image describe the line with start and end point. I already have start and end point for both lines but I am not getting any idea how to calculate the minimum distance between two lines.
Another problem is that how to calculate the minimum distance between two arc.
I am attaching another image here
For arc I have the start, end and center point also I have the start and end angle.
This link has lot more things - Shortest distance between a point and a line segment
I also got help from above link.
This is the another issue what I am facing now. In this scenario how to calculate minimum distance between two arc?
Any idea how solve this two issue?
Let the two segments be AB and CD. Their parametric equations can be written
P = A + u AB, Q = C + v CD, with u, v in [0, 1].
You want to minimize the (squared) distance
PQ² = (CA + u AB - v CD)², under the given constraints,
and you can cancel the first derivatives with
(CA + u AB - v CD).AB = 0
(CA + u AB - v CD).CD = 0
After resolution of the 2x2 system you get a pair (u, v). If both variables fall in [0,1], there is an intersection and the distance is 0.
Otherwise, clamp u and/or v to the relevant bound of range [0, 1] and compute the corresponding distance.
If one variable was clamped, the distance was between an endpoint and a segment; if two were clamped, it's between two endpoints.
A similar approach can be adopted for the arcs (using trigonometric functions), and lead to an optimization problem under linear constraints. Less easy to handle as the objective function is non-linear, though.
We can also proceed as follows:
find the points that make the shortest distance between the whole circles. There are two cases:
the circles intersect, at two places
the circles do not intersect; the shortest distance is between the intersection points of the two circles and the center line.
then check if these points do belong to the arcs by angle comparison. If yes, you are done (the distance is either 0 or the distance between the intersections).
otherwise, consider the endpoints of an arc against the other circle. The closest point is the intersection of the circle with the line through the point and the center. If the intersection belongs to the arc, keep the distance between the point and the intersection. Repeat this for all four combinations endpoint/arc and keep the closest pair.
If no valid pair was found, keep the shortest endpoint/endpoint distance.
The picture shows the distances that can be considered. In green, endpoint/circle; in red, endpoint/endpoint. In this case, the circle/circle distance is zero as they intersect. A distance can be considered if it joins two points inside the arcs.
Distance between two intersecting lines is 0
Otherwise, what you want is to calculate the endpoint of one of the line to the other one.
If you want to calculate the distance between a point and a line :
It is the length of the line segment which joins the point to the line and is perpendicular to the line.
For arcs I think arcs are part of circles, distance between them is the distance between their center points and minus their radiuses.
Probably you can find more here: Calculate the minimum distance between two given circular arcs
Example
Does anyone know how to draw a circular, minor arc given the centre point and two other points that lie on the circle?
I want to draw the pixels directly to the screen, and preferably, not have to calculate the angles.
I am using SDL and C, but may be OK studying code given that uses a different language.
Thanks.
All points on a circle are equal distance to the centre.
Given you know two points on the circle you can calculate this distance.
Assuming you have cartesian coordinates, for every x or y value between the known points calculate the other value so that the point is equal distance to the centre and plot these points.
I think this is conceptually the easiest way, though not the most efficient.
I'm experimenting with a vector based graphics style with objects represented as series of line segments with a given width(it would probably be easier to think of these as rectangles). The problem is that these segments are connected at the center and leave a gap (shown below). I've determined that the most efficient way to cover this gap is simply to cover it with a triangle, and since I'm working in OpenGL, all I need are the points of the two points that don't overlap with the other rectangle, the third point being the center point where the two line segments(rectangles) are connected. How can I determine which points I need to use for the triangle, given that I have all of the points from both rectangles?
EDIT: I will also accept alternative solutions, as long as they cover up that gap.
EDIT 2: Nevermind, I solved it. I'll post code once I have better Internet connection.
Maybe I'm misunderstanding the question... but if you zoom in on the top corner of your red pentagon, you get something like this, am I right?
where A and B are nodes on the rectangle for edge1 and C and D are nodes on the rectangle for edge2. You say you already know these coordinates. And from what you say, the edges meet at the centre, which is halfway between A and B, and also halfway between C and D. So call this point X, and you can calculate its coordinates easily I guess.
So all you need to do is draw the missing triangle AXC, right? So one way would be to determine that A and C are on the "outside" of the polygon (and therefore need filling) and B and D are on the "inside" and therefore don't. But it's probably easier to just draw both, as it doesn't hurt. So if you fill AXC and BXD, you'd get this:
The solution I found assumes that there are 3 basic cases:
First, the three unique center points for the two rectangle proceed upward (positive y direction) so the gap is either on the left or right of the connection. In my code, I had the corner points of the rectangle organized by their orientation to the left or right of the center point, so if the bottom rectangle's left point is below the top rectangle's left point, then the gap is between the left points of the two rectangles, otherwise the gap is between the right points.
Second, the three unique center points have a maximum at the center most of the center points, so the gap is on the top. The gap is then between the two points with the maximum y values.
Third, the three unique center points have a minimum at the center most of the center points, so the gap is on the bottom. The gap is then between the two points with the minimum y values.
[I'll post pictures of the example cases if it is requested]
I have a set of vertices to draw a circle, but I want to draw a high-res circle by drawing twice the number of vertices, I cant just increase the number of vertices what I need is to calculate the mid points from the supplied vertices, if that makes sense
So from that image how can I calculate the points A, B, C, ... given the points V0, V1, V2, ... and the center point of the circle ?
Please note that I cant just calculate the mid-points by rotating the vertices they need to be calculated using their position
Thanks
The center of the circle can be determined by making a perpendicular line to two neighboring "sides", and intersecting them.
If there are an even number of vertices, just pick two which are opposite to each other, and "avarage them" - calculate the midpoint.
Then, you can just rotate all the vertices to either way by 180°/No.vertices around this center, so you get the ones you are looking for. Of course, you should keep the existing ones too.