Say there are 3 circles, A, centered at point a, B centered at point b, and C, centered at point c. Each has a known radius independent of the others, Ar, Br, and Cr. The positions of a and b are known, but the position of c isn't.
The distance between a and b will always be between (Ar + Br) and (Ar + Br + (2 * Cr)).
I'm looking for a pseudo-code algorithm to find the position of c so that circles A and C are tangent, and circles B and C are tangent. There ought to be two solutions unless a and b are at their maximum allowed distance, in which case there would only be one.
Thank you, any help is much appreciated.
"Inflate" the circles A and B by Rc at the same time as you shrink C to a single point. Then the center of C appears as the intersection of the two inflated circles.
Write the implicit equation of the two circles and subtract one from the other; the quadratic terms cancel out, leaving the equation of a straight line (the line through the two intersection points).
(X-Xa)² + (Y-Ya)² = (Ra+Rc)²
(X-Xb)² + (Y-Yb)² = (Rb+Rc)²
=> by subtraction
(Xa-Xb)(2X-Xa-Xb) + (Ya-Yb)(2Y-Ya-Yb) = (Ra-Rb)(Ra+Rb+2Rc)
To solve this, you can express Y as a function of X using the linear relation, then substitute Y in the equation of one of the circles and solve the second degree equation in X, yielding two solutions.
Related
Imagine that we have a triangle where each point is represented using 3 coordinates. How can we tell if a point, which is also represented using 3 coordinates, isn't inside the triangle, but is on the same surface as the triangle ?
Having triangle points A, B, C, we can build vectors
AB = B - A
AC = C - A
and normal vector N using cross product
N = AB x AC
To check whether point P belongs to ABC plane, calculate dot product
AP = P - A
dp = AP.dot.N
dp is equal to zero for points in the plane (use some tolerance to compensate numerical errors)
To find whether point is outside triangle:
choose any non-zero component of normal N (say z-component)
calculate only this component of cross-product of
AB x AP (here we need only (AB.x*AP.y-AB.y*AP.x) to get z-component of result)
BC x BP
CA x CP
If all signs of results are equal (positive or negative) - P is inside, if signs differ - P is outside.
Basically if the points distance to the plane is zero.
Here is my first google hit https://mathinsight.org/distance_point_plane
I am working on an Eye Tracking application, and when I detect the pupil and enveloping it with an ellipse I have to compare it to a ground-truth (exact ellipse around the pupil).
There are always 3 cases of course:
No Overlap >> overlap = intersection = 0
Partial to Perfect Overlap >> overlap = intersection area / ground-truth area
Enclosing >> overlap = intersection area / ground truth
My problem is the 3rd case where e.g. found ellipse is much bigger than the ground-truth hence enclosing it inside so the total overlap is given as 1.0 which is mathematically right but detection-wise not really as the found ellipse doesn't only contain the pupil inside it but other non-pupil parts.
The question is:
What would be the best approach to measure and calculate the overlap percentage between the found and ground-truth ellipses? would be just mere division of the areas?
Please give some insights.
P.S.: I am coding with python and tried to use shapely library for the task as mentioned in the answer to this question as supposedly it does the transform to position the ellipses correctly regarding their rotational angle.
Let R be the reference ellipse, E the calculated ellipse.
We define score := area(E ∩ R) / area(E ∪ R). The larger the score the better the match.
As ∅ ⊆ E ∩ R ⊆ E ∪ R, we have 0 ≤ score ≤ 1, score=0 ⇔ (E ∩ R = ∅) and
score=1 ⇔ E=R.
Consider an ellipse that is completely enclosed by R and has half the area, as well as an ellipse that completely encloses R and has twice the area. Both would have a score of 0.5 . If they were closer to R, for example if the first had 4/5 the area and the second 5/4 the area both would have a score of 0.8 .
I need to mathematically calculate the position [x, y] and the radius where C ∈ N and C is a circle that can be positioned inside another circle with scalable radius and being traversed until reaching a leaf.
Being x the horizontal scale, y the vertical scale and r the radius, I need to infinetely position subcircles inside it, in a perfect geometric form. I've made some math proofs to calculate the density, but I'm not having good results: https://gist.github.com/haskellcamargo/89384ac17ba0131115c7
I define Circle as:
data Shape = Circle Double Double Double deriving (Show)
But I cannot find a deterministic way to prove the x and y position when a circle is inserted inside, with a perfect geometric form.
I found ways to calculate the density of a subcircle, but with special calcs according to the amount of subcircles, but the x and y are variant, with the unique warranty that the composed form where n > 3 will be composed by triangles. I know that I must work on angle, but I'm stuck on this in the last 2 weeks.
The question is: Can I use deterministic calculations to have the position x, y and the radius giving n, being n the number of elements? The final result would be like http://bl.ocks.org/mbostock/7607535, but with the absolute position, as calculated by D3.
I am working on a simple 2D game. In the game, I have a 'robot' that throws a ball towards another robot, in the shape of a parabola. Both 'robots' are positioned on the x axis, aka their y co-ordinates are the same.
The program knows the positions of the two robots, and it knows the position of the vertex.
As I said, I need the ball to travel along the parabola. This means (correct me if I'm wrong), that at any given time, I need to be able to calculate the y position of the ball, since I know it's x position. (Or is there a better way to do this?)
If so, how can I calculate the y position of the ball at any given time, as I said while knowing the location of the parabolas' vertex, and knowing it's two points of intersection with the x axis?
Thanks
EDIT: Please try to make your answers as clear as possible, since my math knowledge is very basic. Thanks
Suppose your parabola is given by P(x) = a x^2 + b x + c. You'll know the formula of the parabola if you know a, b and c. You have three pieces of information:
P(x1) = 0 (Robot 1 is on the ground at x1)
P(x2) = 0 (Robot 2 is on the ground at x2)
P((x1 + x2)/2) = yMax (Half way between the two points the ball is at its maximum)
This is three linear equations in three unknowns (you know x1, x2, yMax, you don't know a, b, c). If you know how to solve three equations in three unknowns, you're all set.
I actually have two questions, I found the answer to the second and didn't update the diagram. I'm not actually sure if these are possible, they really stumped me.
Question 1:
Given point A and e, the angle of the line A is on relative to the x-axis where 0<=e<360 degrees, how do you calculate the coordinates of B? BA is perpendicular to A's line and 1 unit long.
SOLVED: I start by taking the unit vector from a parallel to the x-axis and then I rotate it 90 + e degrees.
Question 2:
I'm using this approach. If anyone has any better suggestions, please let me know.
SOLVED: I find the dot product of the vector from step 1 and the normalized vector AC.
Question 3:
This one should be pretty self-explanatory from the diagram. I need to find the coordinates of C given A, B, the angle of BAC and the distance between A and C.
SOLVED: I rotate BA e degrees and then change the magnitude to d.
If anyone spots problems with my solutions, please comment.
Easy if you understand vectors. Learn about how 2D vectors work and you'll have it. Is that the course you're taking?
Take the unit vector from e to A, knowing that a unit vector has length 1. Assume l1 = xi + yj. The perpendicular vector has components that are the reverse of l1 with one sign changed. In this case, l2 = -yi + xj.
Take the vector l2 that you got from the first problem and transform it as follows:
cx = -cos(t)y - sin(t)x
cy = +sin(t)y + cos(t)x
where t is the rotation angle in radians.
I'll leave the third one for you. Read about 2D vectors and transformations.