Recent

Author Topic: Need procedure for equation of circle defined by 2 pts and tangent line - edit 1  (Read 13048 times)

dculp

  • Full Member
  • ***
  • Posts: 132
Given --
   1) the coordinates of 2 points on a circle (X1,Y1) and (X2,Y2)
   2) a line that is tangent to the circle -- y = mx + b where m is the slope and b is the y-intercept. (The point of tangency isn't known and generally wouldn't be one of the above two points on the circle.)

Find -- the center of the circle (X0,Y0)
Note that the radius of the circle isn't known in advance.

The problem is shown here (https://www.emathzone.com/tutorials/geometry/equation-of-a-circle-given-two-points-and-tangent-line.html).

The solution requires solving a set of nonlinear simultaneous equations. I might be able to do this but the math is tedious and would be error prone. Therefore, I'm looking for a pre-packaged procedure for this.

Thanks for any suggestions,
Don C.

Edit #1 --

Designate the circle center as (X0,Y0). Designate the tangency point as (X3,Y3). The circle radius will be R. These 5 parameters are initially unknown.

Equations to be solved --

1) Y3 = m*X3 + b // equation of tangent line evaluated at (X3,Y3)

2) R^2 = (X1 - X0)^2 + (Y1 - Y0)^2 // square of dist from (X1,Y1) to (X0,Y0)

3) R^2 = (X2 - X0)^2 + (Y2 - Y0)^2 // square of dist from (X2,Y2) to (X0,Y0)

4) R^2 = (X3 - X0)^2 + (Y3 - Y0)^2 // square of dist from (X3,Y3) to (X0,Y0)

5) Y0 + (1/m)*X0 = Y3 + (1/m)*X3 // requires some manipulation to achieve

From the above there are 5 equations in 5 unknowns -- theoretically solvable. However, some of the equations involve squared terms which makes the solution difficult.

Simple (easy) example --

(X1,Y1) = (-2,1)
(X2,Y2) = (+2,1)
m = 0 // horizontal tangent line
b = 0 //  tangent line intersects the Y axis at Y=0
From the last 2 criteria the tangent line must be coincident with the X axis.
The first 2 criteria are symmetric about the Y axis so that the circle center must lie on the Y axis.
The result of these conditions is that the tangent point must lie on the intersection of the X and Y axes -- i.e., (X3,Y3) = (0,0). The original problem now reduces to one with 3 known points on the circle. The results are --
R = 2.5
(X0,Y0) = (0,2.5)

See --
https://www.mathportal.org/calculators/analytic-geometry/circle-through-three-points.php
http://www.ambrsoft.com/TrigoCalc/Circle3D.htm

The above example was easy because m = 0 and b = 0. The problem is significantly more difficult if other conditions for the tangent line are used; hence, my original request.

« Last Edit: February 02, 2021, 03:51:52 am by dculp »

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Need procedure for equation of circle defined by 2 points and tangent line
« Reply #1 on: February 01, 2021, 04:29:22 pm »
Untested, but a bit of high school algebra would give you this:
Code: Pascal  [Select][+][-]
  1. uses
  2.   Math;
  3.  
  4. function X0Y0AreValid(x1, x2, y1, y2, m, b: Single; out x0, y0: Single): Boolean;
  5. var
  6.   denom: Single;
  7. begin
  8.   denom := 2 * (x2 - x1 + m * (y2 - y1);
  9.   Result := Abs(denom) > 0.0000001;
  10.   case Result of
  11.     True: begin
  12.             x0 :=(Sqr(x2) - Sqr(x1) + Sqr(y2) - Sqr(y1) - b) / denom;
  13.             y0 := m * x0 + b;
  14.           end;
  15.     False: begin
  16.              x0 := NaN;
  17.              y0 := NaN;
  18.            end;
  19.   end;
  20. end;
« Last Edit: February 01, 2021, 04:50:42 pm by howardpc »

dculp

  • Full Member
  • ***
  • Posts: 132
howardpc --

Your code requires a ")" in the denom statement. I assume that this should go after x1.

With m = 0 and b = 0 and with (x1,y1) = (-2,1) and (x2,y2) = (+2,1), your result is (x0,x0) = (0,0). The result should be (x0,y0) = (0,2.5) -- see the example in the edit of my original post.

Note that your equation for y0 is a line through the center of the circle, not a line that is tangent to the circle. This can only be corrected if the tangent point (x3,y3) can be determined.


howardpc

  • Hero Member
  • *****
  • Posts: 4144
I merely provided you with a back-of-envelope response that took me no more than 10 minutes, and as I said is completely untested. It was not offered as a reliable solution. I have no use case for this scenario, so have no motivation to write tests or demonstrations of its use which would be needed to provide an acceptable solution.

I hope I have prompted you to work out your own solution, and write tests that verify what you come up with. You have the nous to critique what I offered, so you clearly have the ability to meet your own need with a little effort.

dculp

  • Full Member
  • ***
  • Posts: 132
howardpc --

Perhaps there is a simpler method than the one that I suggested in my edit. Otherwise, solving a system of 5 simultaneous *nonlinear* equations isn't something that may be resolved "with a little effort".

I have searched rather extensively online. The closest solution that I have found is here (https://www.emathzone.com/tutorials/geometry/equation-of-a-circle-given-two-points-and-tangent-line.html). However, the author leaves the final (difficult) part of the solution to the reader. That's why I have turned to this forum for help.

I would still appreciate any suggestions for this problem.


Bart

  • Hero Member
  • *****
  • Posts: 5538
    • Bart en Mariska's Webstek
Mathematics is really long time ago, but:
The line that goes through the midpoint of the linesegment (x1,y1) (x2,y2) and that runs perpendicular to that line segment, also goes throug the midpoint of the circle.
The equation for that line is a first degree polynomial.

Using this info might perhaps give you a slightly less complicated set of equations to solve?
(Untested theory.)

Bart
« Last Edit: February 02, 2021, 01:43:21 pm by Bart »

Bart

  • Hero Member
  • *****
  • Posts: 5538
    • Bart en Mariska's Webstek
Probably not quite that easy as you suggest.
[Edit]In reply to a post by Thaddy, which he later removed.[/edit]

Another thing.
I would simplify the problem by assuming the origin (midpoint) of the circle is at (x=0,y=0).
Makes calculations (and equations simpler).
Since this is a simple translation (is that the correct mathematical term?), it is simple to adjust the coördinates of the given 2 points and the equation for the tangent line, and after finding the solution, just translate back.
(You would in this case want to calculate the radious of course.)

(i.o.w: generalize the solution for the simple case (Origin=(0,0)) to the general case (Origin=(A,B)))

Bart
« Last Edit: February 02, 2021, 01:42:50 pm by Bart »

dculp

  • Full Member
  • ***
  • Posts: 132
Bart --

Unless I am misunderstanding, your analysis (reply #5) isn't correct. The line that connects (X1,Y1) and (X2,Y2) is a chord of the circle. From the midpoint of this chord, the *perpendicular* to this chord will pass through the center of the circle. The slope of this perpendicular line (or the perpendicular to this perpendicular line which is the slope of the chord line) generally won't be the same as the slope m of the tangent line. (Note that the tangent line may be placed anywhere on the circumference of the circle, depending on m and b. On the other hand, the chord line is exactly defined by the choice of (X1,Y1) and (X2,Y2) for which the slope of the chord line is fixed -- call this m'. m' will only equal m under unusual circumstances. )

Please let me know if my thinking is wrong.
« Last Edit: February 02, 2021, 01:44:45 pm by dculp »

Thaddy

  • Hero Member
  • *****
  • Posts: 16673
  • Kallstadt seems a good place to evict Trump to.
Sorry bart, I deleted my entry to solve it properly.
Otherwise people get confused. The above answer is like what I wrote before: finding the point at the circle.
But I am sure they don't want the Trumps back...

balazsszekely

  • Guest
There is no way you can solve that system of equations analytically.  If you know the values of x1, y1, x2, y2, m, n you can attempt a numerical solution:
1. Paste the link from the attached txt into a browser(too long to paste it here)
2. Resize the memo below "Equation(s)"
3. Enter the values for a, b, c, d, m, n then press "Solve"

PS: I wouldn't even attempt to write a program that is able to solve the system of equations numerically. :) It's far from trivial.




Bart

  • Hero Member
  • *****
  • Posts: 5538
    • Bart en Mariska's Webstek
Bart --

Unless I am misunderstanding, your analysis (reply #5) isn't correct. The line that connects (X1,Y1) and (X2,Y2) is a chord of the circle. From the midpoint of this chord, the *perpendicular* to this chord will pass through the center of the circle. The slope of this perpendicular line (or the perpendicular to this perpendicular line which is the slope of the chord line) generally won't be the same as the slope m of the tangent line.
I reralized this 2 seconds after I wrote it and then quickly edited my post.
Seems like you read it before I corrected it.

Please let me know if my thinking is wrong.

You're absolutely correct.

I used to love maths in highschool (I was rather good at it), but since I never ever have to use it in my day job, decline of knowledgde has set in (rot might be a better word)  :-[

Bart

Peter H

  • Sr. Member
  • ****
  • Posts: 272
I tried it, but my higher level mathematics training is 45 years ago.

This said, the modern way to solve equations are Computer Algebra Systems.
In Wolfram Alpha you can write e.g. "solve x^2 + y^2=r^2=x*m for r"
https://www.wolframalpha.com/input/?i=solve+x%5E2+%2B+y%5E2%3Dr%5E2%3Dx*m+for+r
Or:  solve x^2 + y^2=r^2=x*m+c for x,r
https://www.wolframalpha.com/input/?i=solve+x%5E2+%2B+y%5E2%3Dr%5E2%3Dx*m%2Bc+for+x%2Cr
(I do not know the complete syntax, learned it from examples and trial and error)

So you should express your problem in the mathematically most simple -but precise and complete- way and let a Computer Algebra System solve it.
The most simple form of a circle equation is e.g. "(x-c_x)^2+(y-c_y)^2 = r^2" , where "c_x" and "c_y" are the center coordinates.
This needs a lot of typing and I dont know, if the website accepts long expressions pasted from an editor but there are free CAS systems that you can install and use or purchase wolfram alpha, but probably the latter is overkill for such geometric problems.
 8)

You will probably need the formula for the circle and the formula for the orthogonal shortest distance between a point and a line, which is equal to r in this case.
« Last Edit: February 02, 2021, 10:27:08 pm by Peter H »

dculp

  • Full Member
  • ***
  • Posts: 132
GetMem & Peter H --

I appreciate your suggestions. However, I need to incorporate the general solution into a Pascal program so I need the Pascal code (or other code that I can convert to Pascal).

An iterative solution is possible but not the most desirable --

1. Start with a very large radius R.
2. Using R, find a circle with center (X0,Y0) that includes points (X1,Y1) and (X2,Y2). Because R is very large and if the direction of curvature is correctly chosen, the line will be outside the circle.
3. Calculate the minimum distance L from the line to (X0,Y0).
4. Compare L and R. Initially, L > R since the line is outside the circle.
5. Slowly decrease R (deflate the circle) so that it bulges toward the line through the gap (X1,Y1) <--> (X2,Y2).
6. Repeat steps 3, 4, 5 until L = R (the circle just touches the line). Then R is known and all other variables can be calculated.

If the circle's initial direction of curvature is "incorrect" (opposite to above) then the line will intersect the initial large circle at 2 points (forming a chord). Then initially L < R since the line is inside the circle. Then slowly decrease R until L = R (the line touches the circle only at one point -- the point of tangency).

The above should always give a solution. However, it requires a good search algorithm (one that converges but not too many iterations) which is a separate project.

Peter H

  • Sr. Member
  • ****
  • Posts: 272
Given the points and the line, the  problem has only one and only one (not more and not less) solutions, so you should get one formula as a result that is easily written in pascal.
(Unless the two points of the circle are on the line which should be tested before)
In the case of Wolfram Alpha you can also get complex solutions (which contain sqrt(-xyz)), which can be ignored.

Or better said,
you should get one formula for r
one for c_x and one for c_y which is the center of the circle and possibly need r as an argument.

Edit:
I rethought it.
You can always draw two circles that fulfil the condition. If one is small, the other is very large in most cases.
The problem has always two solutions (which cannot be identic) so r should be given as the roots of a quadratic equation.
The problem can be drawn by circle and ruler, so there can be only rational solutions (which can be calculated without iteration or trigonometry) and always two real number solutions (which can be  infinite)
Because quadratic equations have two roots only and always, there are no complex roots and solutions if all coordinates and coefficients are real.

What if the two dots are parallel to the line? You should get one small circle, and, because parallel lines hit in infinite distance, one circle with infinite radius. So the results for r, c_x and c_y should be reziprok to the solutions for a quadratic equation.

Therefore a CAS system can calculate solution formulas without iteration, but I am too tired to do it.  :-\
« Last Edit: February 03, 2021, 03:20:05 am by Peter H »

Peter H

  • Sr. Member
  • ****
  • Posts: 272
I tried it with Wolframalpha, but I am not happy with the result: Computing time exceeded.

https://www.wolframalpha.com/input/?i=solve+r%5E2+%3D+%28x-c_1%29%5E2%2B%28y-c_2%29%5E2+%3D+%28a*c_1+%2Bb*c_2+%2Bc%29%5E2%2F%28a%5E2%2Bb%5E2%29+for+r%2C+c_1%2C+c_2

I am sure there is a (relatively) simple solution.
Note the line equation is here given in the form ax + by + c = 0
c_1 means c_x and c_2 means c_y, because WA does not accept c_x and c_y as names.
« Last Edit: February 03, 2021, 04:33:18 am by Peter H »

 

TinyPortal © 2005-2018