0

I have a point on a half circle that needs a line connecting it to the black half circle. The line goes through the origin of the orange circle (perpendicular). When moving along the upper circle, the length of the line changes. Is there a way to calculate a position for the arrow, so the green line has a length of a given value?
None of the circles are necessarily at the origin.
No need to check if the green line does intersect the black circle, I already made sure that's the case.

enter image description here

  • Please explain how this is a programming question, it currently seems pure math. – Yunnosch Oct 22 '22 at 08:54
  • The orange circle is irrelevant. You only need a formula for the length of the section of the green line from the centre point of the orange circle to the black circle. To get the total length total of the green line you just have to add the radius of the orange circle. – Elec1 Oct 22 '22 at 09:05
  • @Yunnosch , sorry, didn't search enough for the math section, so I thought tagging it math and geometry would get me there. In the end I want to code it, but supplying the math or hints should do. – Frederik Steinmetz Oct 22 '22 at 09:13
  • @Elec1 good point, that's a step in the right direction. – Frederik Steinmetz Oct 22 '22 at 09:14
  • Is that task frequent? Then it might make sense to build a table of "angle on the lower circle" to "length of the line segment", and solve the task by reverse lookup and interpolation in that table. – Lutz Lehmann Oct 23 '22 at 10:26
  • @Lutz Lehmann I think that would be an acceptable approach only if the length of the green line were the only variable parameter. But I suppose that the (relative) location and the radii of both circles may change too. – Elec1 Oct 23 '22 at 16:30

1 Answers1

1

For the length s of the line from the orange centre to the black circle you get the formula:

s^2 = (x + r * cos(a))^2 + (y + r * sin(a))^2

where x is the absolute value of the x-component of the centre of the black circle and y the corresponding y-component. r is the radius of the black circle. a is the angle of the intersection point on the black circle (normally there will be two solutions).

Expanding the given formula leads to:

s^2 = x * x + r * r * cos(a)^2 + 2* r * x * cos(a) 
      + y * y + r * r * sin(a)^2 +2 *r * y * sin(a)

As

r * r * cos(a)^2 + r * r * sin(a)^2 = r * r

we have

s^2 - x^2 - y^2 - r^2 = 2 *r * (x * cos(a) + y * sin(a))   (1)

Dividing by 2*r and renaming the left side of the equation p (p contains known values only) results in

p = x * cos(a) + y * sin(a) = SQRT(x * x + y * y) * sin(a + atan(x / y)) 

==>
a = asin(p /SQRT(x*x + y*y)) + atan(x / y)   (2)

Let's have an example with approximate values taken from your drawing:

x = 5
y = -8
r = 4
s = 12

Then (1) will be

144 = 25 + 16 + 64 + 8 * (5 * cos(a) - 8 * sin(a))  ==>
39 / 8 = 5 * cos(a) - 8 * sin(a) = 

SQRT(25 + 64) * sin(a + atan(5 / -8)) ==>

0.5167 = sin(a + atan(5 / -8))

asin(0.5167) = a - 212°

asin(0.5167) has two values, the first one is 31.11°, the second one is 148.89°. This leads to the two solutions for a: a1 = 243.11° a2 = 360.89° or taking this value modulo 360° ==> 0.89°


I just found a much simpler solution using the Law of cosines:

c * c = a * a + b * b - 2ab * cos(gamma)

You got a triangle defined by three points: the centre points of both circles and the point of intersection on the black circle. The lengths of all three sides are known.

So we get:

cos(gamma) = (a * a + b * b - c * c) / 2ab

If we choose the angle at centre of orange circle to be gamma we get

  • a = sqrt(89) = 9.434 (distance between the centres of both circles)

  • b = 12 (distance between centre of orange circle and point if intersection

  • c = 4 (radius of black circle)

Using this values we get:

cos(gamma) = (89 + 144 - 16) / (2 * sqrt(89) * 12) = 0.9584

gamma = acos(0.9584) = +/- 16.581°

´

Lutz Lehmann
  • 25,219
  • 2
  • 22
  • 51
Elec1
  • 235
  • 2
  • 8
  • it never occured to me to use the angle, good thinking. I'm not sure what exactly is a. You say angle of the intersection point, but with what? The y axis? – Frederik Steinmetz Oct 22 '22 at 11:34
  • The angle a is between the x-axis and the radius (as it is commonly defined in mathematics). When a is increasing the radius rotates counter clockwise. This angle together with the centre of the black circle define the point of intersection between circle and line. – Elec1 Oct 22 '22 at 12:55