Build a geographical map from triangle points based on distance - geometry

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.

Related

The closest point

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

Calculate minimum distance between two lines and two arc

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

Finding closest point to a set of circles

My requirement is to find the point closest to three circles. So lets say the three circles are C1, C2, C3. I want to find the point in the space such that the SUM of its distance from C1, C2 and C3 is MINIMUM.
The distance of a given point from a circle is the distance of the given point from the point that lies on the circle and is intersection of the circle with the line joining the given point with the center of the circle.
Is there a simple logic of find such a point?
Unless one of the distances will be zero, the circle radii are irrelevant: the sum of the distances to the circles will be the sum of the distances to the centers minus the sum of the radii. So in effect you are asking for the geometric median of the circle centers. You might want to iteratively compute an approximation. Or you make use of the fact that you have three circles, in which case the median is the Fermat point of the triangle formed by their centers.
If the point constructed as above lies within one of the circles, then you can move towards that circle while decreasing the sum. So you'd have to consider all the points on that given circle, which you can express as a one-parameter family. You could then compute the distance as a function of that parameter, and the derivative of the resulting formula, and setting that equal to zero will give the optimal solution for this case.

Drawing a circular, minor arc given the centre point and two other points

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.

How to calculate mid point vertices?

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.

Resources