3
$\begingroup$

Context

I am attempting to draw a polygon with 4 or 5 corners using a software library that draws shapes by taking in an array of corners in the form of $(X,Y)$. I am somewhat woefully under skilled in my understanding of geometry here, and looking for either the formulas to solve my problem or some good directions to tutorials, videos, and other learning tools, or both.

Givens

I have two circles defined by their centers and their radius $A_c, A_r, B_c, B_r$ and the bounding box extends from $(0,0)$ to some corner, $(BB_X,BB_Y)$.

This produces either eight or ten values I want to calculate. The shape I want is represented by the pink shaded area, and the points I need to produce it by the green stars.

enter image description here

The Question

What formulas do I use to calculate these 4 or 5 points?

or

What are some concepts/tools/videos I can use to learn how to construct the formulas to calculate these 4 or 5 points?

$\endgroup$
3
  • 1
    $\begingroup$ Calculate the intersection of the tangents (from similar triangles). Then write the equation of the two stars on the circle using en.wikipedia.org/wiki/…. Calculate the intersection with the sides in the same half plane as the circle center from the line perpendicular to $A_C,B_C$ at the intersection point. If the distance $A_C,B_C$ is greater than the sum $A_r+B_r$, then you might get up to 7 stars $\endgroup$
    – Andrei
    Commented Nov 3, 2023 at 15:31
  • $\begingroup$ This might help you askiitians.com/iit-jee-coordinate-geometry/…)). $\endgroup$
    – user1233641
    Commented Nov 3, 2023 at 15:33
  • $\begingroup$ Please see the answer by Jan-Magnus on the dual conic approach. The crux of your calculation is finding the equations of the common tangent lines. From there, you can calculate the rest of the points. math.stackexchange.com/questions/3436714/… $\endgroup$
    – Doug
    Commented Nov 3, 2023 at 15:50

2 Answers 2

1
$\begingroup$

I'm going to replace the variable names $A_c, A_r, B_c, B_r$ with $C_1, r_1, C_2, r_2$ respectively.

There are several ways to tackle finding the the internal tangents between two disjoint circles. The following method uses vector and trigonometric expressions.

Consider a point $P(t)$ on the second circle, it is given by

$ P(t) = C_2 + r_2 (\cos t , \sin t ) $

The vector $(\cos t, \sin t)$ is a vector that is perpendicular to the tangent line to the circle at $P(t)$. It is pointing outward of the circle. The equation of the tangent line at $P(t)$ is,

$ (\cos t, \sin t ) \cdot ( (x, y) - P(t) ) = 0 $

We want the (signed) distance between the center of the first circle and this tangent line to be $r_1$. Hence,

$r_1 = (\cos t , \sin t ) \cdot ( C_1 - P(t) ) $

Substitute $P(t)$, you get

$ r_1 = (\cos t, \sin t ) \cdot (C_1 - C_2 - r_2 (\cos t, \sin t) )$

This simplifies to

$ r_1 = (\cos t, \sin t ) \cdot ( C_1 - C_2 ) - r_2 $

Therefore, we want to solve

$ (\cos t , \sin t ) \cdot (C_1 - C_2) = r_1 + r_2 $

If $ V = (V_x, V_y) = C_1 - C_2 $

Then

$V_x \cos t + V_y \sin t = r_1 + r_2 $

There are two solutions to this trigonometric equation, and they are given by

$ t = ATAN2( V_x, V_y ) \pm \cos^{-1} \left( \dfrac{ r_1 + r_2 }{ \sqrt{V_x^2 + V_y^2} } \right) $

The $ATAN2$ function is a standard math library function, and returns the angle $t$, which is the angle between the positive $x$ axis and the line segment extending from $(0,0)$ to $(V_x, V_y)$.

We now have two values of $t$ obtained from the above formula, so we have the equations of the two tangents.

Next, starting from $P(t)$ (where $t$ is one of the two values obtained above), we want to determine which way to move along the tangent line to meet the first circle. To do that, rotate the normal vector which is $(\cos t, \sin t)$ by $90^\circ$ counter clockwise to obtain $d(t) = (-\sin t , \cos t )$. To determine where this is the right direction to move (along the tangent line from the the second circle (B) to the first circle (A) ), calculate

$ d(t) \cdot (C_1 - C_2 ) $

if this is positive, then $d(t)$ is the right direction, otherwise we have to reverse its direction.

Now you can intersect the tangent line

$Q(s) = P(t) + s d(t) , \ s \ge 0 $

with the borders of the bounding rectangle. There are four sides whose cartesian equations are known. Substitute $Q(s)$ into the equation of each border , and solve for $s$. If $s$ is negative then discard that intersection.

In addition, you need the touching points between the tangent lines and the first circle (circle A). This distance $s$ along the direction $d(t)$ is given by

$ s = (C_1 - C_2) \cdot d(t) $

(Projection of the vector $(C_1 - C_2)$ along the unit vector $d(t)$).

Finally you want to add the corner points. To choose which corner point to include in the set of vertices of the polygon, let $E$ be a corner point, then compute the following

$ (E - P(t) ) \cdot (\cos t , \sin t ) $

If $E$ is to be included, then this quantity must be positive for both values of $t$.

$\endgroup$
4
  • 1
    $\begingroup$ @Suni What do you think of my solution? Does it make sense ? If it solves your question, then please upvote and accept the answer. If not, I'm ready to discuss any concerns you might have. $\endgroup$ Commented Nov 5, 2023 at 9:47
  • $\begingroup$ This absolutely contains my answer, but it also contains a few concepts I'm failing to keep up with. I think it's enough I can google my way back out, but if you don't mind I'll add my questions here in case you're willing to answer, or in case it helps you clarify the answer to your satisfaction. $\endgroup$
    – Suni
    Commented Nov 5, 2023 at 17:58
  • $\begingroup$ Questions - The t in $P(t)$ is can be thought of as angle of the tangent point in radians? - After you substitute $P(t)$ in I don't understand where the 0 comes from? Particularly it looks like the equation says $r_1 = 0$? - I fail to have a visual intuition for what V represents so far (continuing to study and read up) - I don't know how to substitute $Q(s)$ into the equations for the lines of the rectangle. $\endgroup$
    – Suni
    Commented Nov 5, 2023 at 18:16
  • 1
    $\begingroup$ Yes. $t$ is an angle in radians. The $0$ is there by mistake, there is no $0$. I'll correct this shortly. As for $Q(s)$ it is as defined , if the equation of one of borders is M^T ( (x,y) - (x_0, y_0) ) = 0 $ Then after substituting Q(s) , you will get $ M^T ( Q(s) - (x_0, y_0) ) = 0 $ $\endgroup$ Commented Nov 5, 2023 at 18:46
1
$\begingroup$

This is not an answer, but I wanted to paste the figure with 7 points you might need to calculate enter image description here

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .