How to find position using triangulation method having 3 points and 3 radii - math

So I have 3 points let's say
A1 = (x1,y1), A2 = (x2,y2), A3 = (x3,y3)
and I am located at S = (x,y) and I know that my distance from the 3 points are d1, d2, d3
I want to calculate my position using triangulation method. I managed to do it with trilateration method but I also have to use triangulation. I am kind of confused how to approach this and I would appreciate any help. Thanks

Related

How can we plot quadrilateral (all known length) in ggplot?

Suppose we have a quadrilateral (piece of land) of known side lengths. How can we plot it ( using geom_point/geom_poly) in ggplot?
The measurements are: AB = 11.55, BC = 17.17, CD = 11.77, DA = 15.76
Diagonal: BD = 20.20, AC = 20.34
A can be set as origin. We can assume AB is along x axis.
Edit 1 -
The quadrilateral has four landmarks in each corner. I found the distances from google map (using measure distance). Now, I want to plot this quadrilateral on ggplot.
Edit 2 -
There is no unique quadrilateral. The measured distance may not be very accurate (plus/minus 0.5 meter)

Calculate points on surface of 3d model

I have a 3d model (from Blender) with vertices, vertices normals (normalized) and faces (triangles). I need to calculate additional vertices and their normals. Other words, I need algorithm to calculate center vertex for triangle from three vertices and three vertices normals.
For example, in picture we have A, B, C vertices. How to calculate D vertex and it's normal?
Or, even better, point E (center of one of the sides).
Could anybody help me?
If you want point D lie exactly on plane based on ABC then I suggest you to use barycentric coordinates. Point D is intersection of medians and it is (1/3, 1/3, 1/3) in barycentric coordinates, or D = 1/3A + 1/3B + 1/3C, E would be (0,1/2,1/2). The normal ND should be calculated in the same way as D, ND = 1/3NA + 1/3NB + 1/3NC.
You didn't state the reason why do you need to calculate D and E. I suppose you want to get more triangles in the mesh, thus better level of detail. In this case PN-triangles should be used

How to find two points along an existing line

I'm sure this is basic trigonometry, and I bet I covered at school many years ago, but I struggle knowing what function to apply to a real world situation. Anyway, rather than try and explain what I need help with, I've drawn a little diagram:
I know p1, p2, r1 and r2 but I can't remember (or know how to search for) how to work out what p3 and p4 are.
The basic application of this setup is I have 2 circles (red and blue) and I need them constantly connected as I drag them around the canvas. The pink link will connect them via their centre points but I don't want the line to penetrate the circle's circumferences.
Hope that makes sense? Thanks in advance.
this is simple vector math (no trigonometry needed)
create unit vector v with P1 to P2 direction
That is easy in vector form:
v=P2-P1; v/=|v|
And when put into 2D:
v.x=P2.x-P1.x;
v.y=P2.y-P1.y;
l=sqrt((v.x*v.x)+(v.y*v.y))
v.x/=l;
v.y/=l;
Now just translate from P1,P2by r1,r2
Vector form:
P3=P1+r1*v
P4=P2-r2*v
In 2D:
P3.x=P1.x+r1*v.x;
P3.y=P1.y+r1*v.y;
P4.x=P2.x-r2*v.x;
P4.y=P2.y-r2*v.y;
You have to solve the following equation system:
For p3 -->
(X-p1x)/(p1x-p2x)=(Y-p1y)/(p1y-p2y)
(X-p1x)^2 + (Y-p1y)^2 = r1^2
The same for p4 just change r1 for r2 and p1 for p4 in the second equation.
The first equation is the equation of a line given 2 points.
And the second equation is the equation of a circle given a center point and a radius.
The resulting X, Y values will be the values of p3, and then p4.
Let d be the distance between p1(x1, y1) and p2(x2,y2)
Thus
d = sqrt((x1-x2)^2 + (y1-y2)^2)
Now point p3(x3, y3) divides the line between p1 and p2 in the ratio of r1:(d-r1)
Thus
x3 = (r1*x2 + (d-r1)*x1)/d and
y3 = (r1*y2 + (d-r1)*y1)/d
Similarly for p4(x4, y4)
x4 = (r2*x1 + (d-r2)*x2)/d and
y4 = (r2*y1 + (d-r2)*y2)/d
What I am going to say is a little long. I will let you write your own code, however, of course will not help with that.
You know points P1, P2, and radius R1 and R2. Say suppose points P1 and P2 have coordinates (x1,y1) and (x2,y2) respectively.
The line connecting P1 and P2 is a straight line and hence you can calculate the slope of the line using the formula m=(y2-y1)/(x2-x1). Since you know the slope and know two coordinates, you can calculate the intercept c and construct a formula of the form y=mx+c.
Once the line formula is there, you can apply values for x and calculate y for point P3, lets say x3 and y3 since you have the radius R1. Similarly, calculate the coordinates for P4.

R Find the point of intersection of two lines connecting 4 coordinates

I apologize in advance if my code looks very amateurish.
I'm trying to assign quadrants to 4 measurement stations approximately located on the edges of a town.
I have the coordinates of these 4 stations:
a <- c(13.2975,52.6556)
b <- c(14.0083,52.5583)
c <- c(13.3722,52.3997)
d <- c(12.7417,52.6917)
Now my idea was to create lines connecting the north-south and east-west stations:
line.1 <- matrix(c(d[1],b[1],d[2],b[2]),ncol=2)
line.2 <- matrix(c(a[1],c[1],a[2],c[2]),ncol=2)
Plotting all the stations the connecting lines looks allright, however not very helpful for analyzing it on a computer.
So I calculated the eucledian vectors for the two lines:
vec.1 <- as.vector(c((b[1]-d[1]),(b[2]-d[2])))
vec.2 <- as.vector(c((c[1]-a[1]),(c[2]-a[2])))
which allowed me to calculate the angle between the two lines in degrees:
alpha <- acos((vec.1%*%vec.2) / (sqrt(vec.1[1]^2+vec.1[2]^2)*
sqrt(vec.2[1]^2+vec.2[2]^2)))) * 180/pi
The angle I get for alpha is 67.7146°. This looks fairly good. From this angle I can easily calculate the other 3 angles of the intersection, however I need values relative to the grid so I can assign values from 0°-360° for the wind directions.
Now my next planned step was to find the point where the two lines intersect, add a horizontal and vertical abline through that point and then calculate the angle relative to the grid. However I can't find a proper example that does that and I don't think I have a nice linear equation system I could solve.
Is my code way off? Or maybe anyone knows of a package which could help me? It feels like my whole approach is a bit wrong.
Okay I managed to calculate the intersection point, using line equations. Here is how.
The basic equation for two points is like this:
y - y_1 = (y_2-y_1/x_2-x_1) * (x-x_1)
If you make one for each of the two lines, you can just substitute the fractions.
k.1 <- ((c[2]-a[2])/(c[1]-a[1]))
k.2 <- ((b[2]-d[2])/(b[1]-d[1]))
Reshaping the two functions you get a final form for y:
y <- (((-k.1/k.2)*d[2]+k.1*d[1]-k.1*c[1]+d[2])/(1-k.1/k.2))
This one you can now use to calculate the x-value:
x <- ((y-d[2])+d[1]*k.2)/k.2
In my case I get
y = 52.62319
x = 13.3922
I'm starting to really enjoy this program!
Wikipedia has a good article on finding the intersection between two line segments with an explicit formula. However, you don't need to know the point of intersection to calculate the angle to the grid (or axes of coordinate system.) Just compute the angles from your vec.1 and vec.2 to the basis vectors:
e1 <- c(1, 0)
e2 <- c(0, 1)
as you have done.

Finding Two Touching circles with limited information

I am working on a track editor and have found myself in a situation where I need to define two touching circles. Ideally I would like to know the centre point, and radius of these circles.
The information I have is a point on the circumference of each of the circles, and the tangent to the circle at that point.
On my own I have figured out that if I know the tangents at those points I know the lines on which the centre points must lie.
C1 is the centre of the first circle I am looking for
P1 is a point on the circumference of the circle at which I know the tangent
A is the normal to the tangent that I know at P1
C2 is the centre of the second circle I am looking for
P2 is a point on the circumference of the circle at which I know the tangent
B is the normal to the tangent that I know at P2
C1 = P1 - t1 * A
C2 = P2 - t2 * B
I also know that the distance between the two centres will be equal to the sum of the distance of the centres from the points on the circumference.
|C1 - P1| + |C2 - P2| = |C1 - C2|
I also want abs( |t1*A| - |t2*B| ) to be kept to a minimum.
If you have only the tangent vectors and the point, there's not enough information. You need at least 2 more points, one more for each circle, otherwise t1 and t2 can be any real. (By the way, A = -B)
Disregard, I assumed that circles are not overlapping. Either way, we cannot know how large they are (and hence where the center points are) without knowing more information.

Resources