How to find a tangent point from a circle?
조회 수: 7 (최근 30일)
이전 댓글 표시
I have a code to find a tangent point from a circle.I have used the circle radius as 2000.For all the points on the circle it will find the tangential point for the given radius. But when the point lies exactly on the same line then the vector point will be NAN for the given radius,if the radius changed then the vector is having answer why?Here i have displayed code for finding points.kindly give answer.
x1=200000;y1=15000;
x2=350000;y2=20000;
z1=200;z2=200;
x3,y3,z3=[230000 16000 200];
Radius=2000;
a11=((x2-x1)^2+(y2-y1)^2+(z2-z1)^2);
b11=2*(((x2-x1)*(x1-x3))+((y2-y1)*(y1-y3))+((z2-z1)*(z1-z3)));
c11=x3.^2+y3.^2+z3.^2+(x1^2)+(y1^2)+(z1^2)-2*((x3*x1)+(y3*y1)+(z3*z1))-(Radius*Radius);
condn1=(b11*b11)-(4*a11*c11);
condition=abs(condn1);
t=(-b11+(sqrt((condition))))/(2*a11);
t1=(-b11-(sqrt((condition))))/(2*a11);
Xi=x1+(x2-x1)*t;
Yi=y1+(y2-y1)*t;
Zi=z1+(z2-z1)*t;
Xf=x1+(x2-x1)*t1;
Yf=y1+(y2-y1)*t1;
Zf=z1+(z2-z1)*t1;
v1 = [Xi-x3;Yi-y3;Zi-z3];
radius = norm(v1);
v2 = [Xf-x3;Yf-y3;Zf-z3];
v3 = cross(cross(v1,v2),v1);
v3 = radius*v3/norm(v3);
t = linspace(atan2(norm(cross(v1,v2)),dot(v1,v2)),0,5);
vec = v1*cos(t)+v3*sin(t);
XVec=vec(1,:)+x3
YVec=vec(2,:)+y3
ZVec=vec(3,:)+z3
댓글 수: 1
채택된 답변
KSSV
2018년 1월 3일
Refer this link for what you want: https://in.mathworks.com/matlabcentral/answers/258780-how-to-plot-tangent-line-from-specified-point-to-a-circle
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!