How can I draw a tangent line from a given point to a circle in Matlab
4 views (last 30 days)
Show older comments
Hi I am trying to draw a tangent line from a given external point to a circle of known radius and origin as the center
Please help
3 Comments
dpb
on 4 Sep 2013
The obvious is that the radius and the tangent line must be normal to each other so the three points have to form a right triangle...
Accepted Answer
Roger Stafford
on 5 Sep 2013
Let P1 be a 1 x 2 row vector of the external point's cartesian coordinates and P2 a similar vector of the circle's center coordinates. Let r be the circle's radius. Then Q1 and Q2 below will be the two possible points of tangency of a line from P1. Q1 is to the right and Q2 to the left as viewed from P1 looking toward P2.
P = P1-P2;
d2 = dot(P,P);
Q0 = P2+r^2/d2*P;
T = r/d2*sqrt(d2-r^2)*P*[0,1;-1,0];
Q1 = Q0+T;
Q2 = Q0-T;
4 Comments
Antonio Cantiani
on 21 May 2016
I would like to understand the mathematics behind this. Can someone explain it, please?
Roger Stafford
on 22 May 2016
@Antonio: This is a brief outline of the derivation of the above expressions. If the points Q1 and Q2 are connected with a straight line, this line will cross the line between P1 and P2 at a right angle by symmetry, and the point Q0 is defined as the point where these lines cross. The four points P1, P2, Q1,and Q0 when connected form three similar right triangles and the expression for Q0 as P2+r^2/d2*P can be deduced from some of the like ratios involved in these triangles. The vector P*[0,1;-1,0] points at right angles to the vector P, and the expression for T which points from Q0 to Q1 can also be derived from these similar triangle ratios, along with the Pythagorean theorem. By symmetry -T points in the opposite direction from Q0 to Q2.
More Answers (0)
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!