Point position in a circle
Hello again the first part works like a charm, thanks everyone.
But I have another question ...
Since I don't have an interface, is there a way to do the same without knowing the radius of the circle?
The page needs to be refreshed. CodeMonkey's solution is exactly what I was looking for ...
Thanks again.
=============================
Firstly, I am not a developer, I am a simple woodworker who left school too early ...
I am trying to make one of my autonomous robot work tools. I got them to chat by reading a lot of tutorials.
But I have one problem that I cannot figure out.
Robot expects tool position as (X, Y) but tool result (A, B, C) A is tool distance to north B distance to east C 120 degrees clockwise from east ax
the border is a circle, the radius may change and may or may not be something I know.
I've been doing this for 1 month now and I can't seem to find a way to convert this value to position.
I did a three-nail test in a circle that I draw on a tree and if I have a distance, only one position is possible, so I think it is possible. But how?
Also, if someone as an answer I would like the pseudo code and not the code so that I can practice.
If there is a drawing tool that I can use to make it clearer, can you point it to me?
Thank.
hope this helps:
X, Y - coordinates from the center, Da, Db, Dc are known.
Trying to make it clearer (sorry, so clear in my head).
X, Y - coordinate of the point where the tool is (P). Center is at 0.0
A is the point where the vertical line cuts the circle from P, and the distance Da from P to A;
B is the point at which the horizontal line cuts the circle fom P, with a distance Db P to B.
C is the point at which a line 120 clockwise from the horizontal cuts the circle from P, and the distance Dc from P to C.
The output from the tool is an array of int (unit mm): A = 123, B = 114, C = 89 This is the only information I have
thanks for all the ideas I will try at their home later, Hope it works :)
source to share
Suppose you know X and Y. R is the radius of the circle.
|(X, Y + Da)| = R
|(X + Db, Y)| = R
|(X - cos(pi/3) * Dc, Y - cos(pi/6) * Dc)| = R
Assuming we do not know the radius R. We can still say
|(X, Y + Da)|^2 = |(X + Db, Y)|^2
=> X^2 + (Y+Da)^2 = (X+Db)^2 + Y^2
=> 2YDa + Da^2 = 2XDb + Db^2 (I)
and denoting cos (pi / 3) * Dc as c1 and cos (pi / 6) * Dc as c2:
|(X, Y + Da)|^2 = |(X - c1, Y - c2)|^2
=> X^2 + Y^2 + 2YDa + Da^2 = X^2 - 2Xc1 + c1^2 + Y^2 - 2Yc2 + c2^2
=> 2YDa + Da^2 = - 2Xc1 + c1^2 - 2Yc2 + c2^2
=> Y = (-2Xc1 + c1^2 + c2^2 - Da^2) / 2(c2+Da) (II)
Returning (II) to equation (I), we get:
=> (-2Xc1 + c1^2 + c2^2 - Da^2) Da / (c2+Da) + Da^2 = 2XDb + Db^2
=> (-2Xc1 + c1^2 + c2^2 - Da^2) Da + Da^2 * (c2+Da) = 2XDb(c2+Da) + Db^2 * (c2+Da)
=> (-2Xc1 + c1^2 + c2^2) Da + Da^2 * c2 = 2XDb(c2+Da) + Db^2 * (c2+Da)
=> X = ((c1^2 + c2^2) Da + Da^2 * c2 - Db^2 * (c2+Da)) / (2Dbc2 + 2Db*Da + 2Dac1) (III)
Knowing X, you can get Y by calculating (II).
You can also do some simplifications, for example. c1 ^ 2 + c2 ^ 2 = Dc ^ 2
Introducing this in Python (almost pseudocode):
import math
def GetXYR(Da, Db, Dc):
c1 = math.cos(math.pi/3) * Dc
c2 = math.cos(math.pi/6) * Dc
X = ((c1**2 + c2**2) * Da + Da**2 * c2 - Db * Db * (c2 + Da)) / (2 * Db * c2 + 2 * Db * Da + 2 * Da * c1)
Y = (-2*X*c1 + c1**2 + c2**2 - Da**2) / (2*(c2+Da))
R = math.sqrt(X**2 + (Y+Da)**2)
R2 = math.sqrt(Y**2 + (X+Db)**2)
R3 = math.sqrt((X - math.cos(math.pi/3) * Dc)**2 + (Y - math.cos(math.pi/6) * Dc)**2)
return (X, Y, R, R2, R3)
(X, Y, R, R2, R3) = GetXYR(123.0, 114.0, 89.0)
print((X, Y, R, R2, R3))
I get the result (X, Y, R, R2, R3) = (-8.129166703588021, -16.205081335032794, 107.1038654949096, 107.10386549490958, 107.1038654949096)
Which seems reasonable, if both yes and Db are longer than Dc, then both coordinates are probably negative.
I calculated the Radius from three equations to see if my calculation makes sense. It seems to fulfill all three equations that we set at the beginning.
source to share
Basic geometry. I decided to give up the circle in origin. We don't know the center of the circle yet. What you have are three points on this circle. Try to have the tool position specified as P as new (0,0). Thus, he decides to find a circle defined by three points: (0, Da); (Db, 0) and retreat at 120 ° at a distance of Dc.
pseudocode:
- Calculate the string from A to B: we'll call it AB. Find the intersection point AB. Calculate a line perpendicular to AB through this midpoint (for example, the cross product of AB and the ZZ axis will find the perpendicular vector).
- Calculate a string from B to C (or C to works just as well): we'll call it BC. Find BC halfway. Calculate a line perpendicular to BC through this midpoint.
- Calculate where the two lines intersect. This will be the origin of your circle.
Since P is at (0,0), the negative from your start of the circle will be the coordinate of your tool relative to the start of the circle. Now you will be able to calculate whatever you need regarding this.
Midpoint between two points: X = (X1 + X2) / 2. Y = (Y1 + Y2) / 2.
The radius of the circle can be calculated using, for example, point A and the start of the circle: R = sqrt (sqr ((Ax-CirX) + sqr (Ay-CirY))
Distance from edge: The radius of the circle is the tool's distance from the center of the circle using the Pythagorean theorem again.
source to share
Your problem is a "limited circle". You have a triangle defined by three distances at given angles from the position of your robot, then you can build a circumscribed circle from these three points (see Wikipedia's Environment Loop - Other Properties section ). This means you know the diameter (if necessary).
It is also known that the meeting point of the perpendicular bisector of the triangular sides is the center of the circumscribed circle.
source to share
Let a=Da, b=Db
. We can write a system for points A and B in a circle:
(x+b)^2 + y^2 = r^2 (y+a)^2 + x^2 = r^2
After transformations, we have the quadratic equation
y^2 * (4*b^2+4*a^2) + y * (4*a^3+4*a*b^2) + b^4-4*b^2*r^2+a^4+2*a^2*b^2 = 0
or
AA * y^2 + BB * y + CC = 0
where coefficients are
AA = (4*b^2+4*a^2)
BB = (4*a^3+4*a*b^2)
CC = b^4-4*b^2*r^2+a^4+2*a^2*b^2
So, calculate the coefficients AA, BB, CC, find the solutions y1, y2 of the quadratic equation, then get the corresponding values of x1, x2 using
x = (a^2 - b^2 + 2 * a * y) / (2 * b)
and pick a couple of real solutions (where the coordinate is inside the circle)
Quick check: a=1,b=1,r=1
gives coordinates 0,0
as expected (and false 1,-1
outside the circle) a=3,b=4,r=5
gives coordinates (rough) 0.65, 1.96
in the image, distances around 3 and 4.
Delphi code (doesn't check all possible errors) exits x: 0.5981 y: 1.9641
var
a, b, r, a2, b2: Double;
aa, bb, cc, dis, y1, y2, x1, x2: Double;
begin
a := 3;
b := 4;
r := 5;
a2 := a * a;
b2:= b * b;
aa := 4 * (b2 + a2);
bb := 4 * a * (a2 + b2);
cc := b2 * b2 - 4 * b2 * r * r + a2 * a2 + 2 * a2 * b2;
dis := bb * bb - 4 * aa * cc;
if Dis < 0 then begin
ShowMessage('no solutions');
Exit;
end;
y1 := (- bb - Sqrt(Dis)) / (2 * aa);
y2 := (- bb + Sqrt(Dis)) / (2 * aa);
x1 := (a2 - b2 + 2 * a * y1) / (2 * b);
x2 := (a2 - b2 + 2 * a * y2) / (2 * b);
if x1 * x1 + y1 * y1 <= r * r then
Memo1.Lines.Add(Format('x: %6.4f y: %6.4f', [x1, y1]))
else
if x2 * x2 + y2 * y2 <= r * r then
Memo1.Lines.Add(Format('x: %6.4f y: %6.4f', [x2, y2]));
source to share
In your diagram, you have a point P
where you need coordinates X
and Y
. Therefore, we need to find Px
and Py
or (Px,Py)
. We know that Ax = Px
and By = Py
. We can use them to replace them if needed. We know that C
they are P
creating a line, and all the lines have a slope in the form y = mx + b
. Where is the slope m
and the y-intercept is b
. We do not know m
or b
at this point, but they can be found. We know that the angle between two vectors, where vectors CP
and PB
, gives the angle 120°
, but this does not put the angle to its standard position, since this is a rotationCW
... When working with circles and trigger functions along with linear slope equations within them, it is best to work in standard form. So, if this line y = mx + b
, where the points C
and refer to it P
, the angle above the horizontal line parallel to the horizontal axis, which is produced by the points P
and b
, will be 180° - 120° = 60°
We also know that the angle cos between two vectors is also equal to the dot product of those vectors that are divided by the product of them quantities.
We don't have the exact numbers yet, but we can build a formula: Since theta = is 60°
higher than the horizontal at the standard position, we know that the slope is m
also tangent to that angle; therefore the slope of this line is tan (60 °). So let's go back to our linear equation y = tan(60°)x + b
. Since it b
is an interception Y
, we need to find what X
, when Y
equals 0
. Since we still have three undefined variables Y
, X
and b
, we can use the dots on this line to help us here. We know that the points C
and P
are on the line. So this vector is y = tan(60°)x + b
built from (Px, Py) - (Cx, Cy)
. A vector then (Px-Cx, Py-Cy)
that has an angle60°
above the horizon, which is parallel to the horizontal axis. We need to use a different form of linear equation that includes the points and slope this time, which happens y - y1 = m(x - x1)
, so this becomes y - Py = tan(60°)(x - Px)
. I said earlier that we can replace so that let's move on:, y - By = tan(60°)(x - Ax)
then y - By = tan(60°)x - tan(60°)Ax
. And this will become known if you know the actual coordinate points A
and b
. The only thing you need is to convert your corner 120°
to a standard shape. It all depends on your known and unknown. Therefore, if you need P
, and you have both A
, and b
as you know from the diagram, the job is simple, because the points you need for P
will be P(Ax,By)
. And as you said, you know Da
,Db
and Dc
with their length, it is simply a matter of applying the correct trigger functions with the correct angle and / or using the Pythagorean theorem to find the length of the other leg of the triangle. It's not that hard to find that P(x,y)
from other points. You can use trigger functions, linear equations, Pythagorean theorem, vector calculations, etc. If you can find the equation of the line that indicates C
and P
, knowing what P
matters A's
X
and what matters B's
Y
and has the slope of this line, which is determined by the tangent above the horizontal, which is equal to 180° - phi
, where phi
is the angle that you specify, it is CW
rotation and theta
whether it is the angle at standard position or above horizontal, you have a general viewy - By = tan(180° - phi)(x - Ax)
and from this equation you can find any point on that line.
There are other methods as well, such as using existing points and vectors they create between themselves and then generate an equilateral triangle using those points and then from this equilateral one, if you can create one, you can use the perpendicular bisectors of this triangle to find the center of gravity of this triangle. This is another method that can be done. The only thing you might have to consider is the linear translation of the line from the origin. This way you will have an offset in the line (Ax - origin, By - origin), and to find one, set the other to 0 and vice versa. There are many different ways to find it.
I just showed you some mathematical methods to help you find the general equation based on your known (s) and unknown (s). It's just a matter of what equations work in this scenario. When you find out the correct equations for the givens; the rest is pretty simple. I hope this helps you.
EDIT
I forgot to mention one thing; and this line CP
has a point at the edge of the circle, defined (cos(60°), sin(60°))
in the 1st quadrant. In the third quadrant, you will have a point on this line, and a circle defined (-cos(60°), -sin(60°))
assuming that this line passes through the origin (0,0)
, where there are no interceptions Y
and X
, and if so, then the point on the circle at both ends and the origin will be the radius of this circle ...
source to share