Joh*_*lla 38
给定具有第一端点P(x1,y1)的线,另一个端点是未知的,与位于原点的圆相交,其中半径R仅在一个点(切线)T(x2,y2)处.谁知道如何得到点T?
其他一些解决方案看起来有点像矫枉过正.我认为最简单的方法就是注意这是一个直角三角形,顶点为P,T和O(原点).角度PTO是直角,因为切线始终与半径成直角.
你知道TO它的长度因为它的长度r并且在原点有一个顶点; 你知道OP,因为你知道在哪里O以及P是.给定直角三角形的两边,很容易找到第三边的长度和方向.这是家庭作业,所以我将把剩下的作为练习留给读者.
__...------__ T(x2, y2)
_.-'' -(+)
,-' |----
,' | ----
,' | ' ----
/ | ` ----
/ | `. ----
/ | \ ----
| | | ----
| | | ----
| | | ----
| (+)---------------------------------------------(+) P (x1,y1)
| .'
| O |
| .'
\ /
\ ,'
` /
'. ,'
'-. _,'
'-._ _,(+) T'(x3, y3)
'`--......---'
Run Code Online (Sandbox Code Playgroud)
有两种可能的方向TO,因为点T'也是一个有效的切点,所以你将有两个全等三角形.
imb*_*izi 16
你需要的只是dmckee的答案,但如果你关心一些代码,请使用Javascript和HTML canvas检查这个实现.
完整示例: http ://jsfiddle.net/zxqCw/1/
// find tangents
dx = cx - px;
dy = cy - py;
dd = Math.sqrt(dx * dx + dy * dy);
a = Math.asin(radius / dd);
b = Math.atan2(dy, dx);
t = b - a
ta = { x:radius * Math.sin(t), y:radius * -Math.cos(t) };
t = b + a
tb = { x:radius * -Math.sin(t), y:radius * Math.cos(t) };
Run Code Online (Sandbox Code Playgroud)
取R圆的半径和D从外部点到圆心的距离D > R.
tanget线\alpha与连接外部点和中心的线形成角度,其中
\alpha = arcsin(R/D)
Run Code Online (Sandbox Code Playgroud)
连接外部点(P)和中心(C)的线与水平面成一个角度
\beta = arctan((C_y - P_y)/(C_x - P_x))
Run Code Online (Sandbox Code Playgroud)
这将为您提供切线与水平线的角度
\theta = \beta +/- \alpha
Run Code Online (Sandbox Code Playgroud)
注意模棱两可.
切线段的长度为
L = sqrt(D^2 - R^2)
Run Code Online (Sandbox Code Playgroud)
这就是你所需要的.
小智 7
imbrizi的答案假设圆的中心是(0,0).
这是目标C中的正确答案:
- (NSArray *)pointsTangentToCircleWithCenter:(CGPoint)centerPoint
radius:(CGFloat)radius
outerPoint:(CGPoint)outerPoint {
float dx = centerPoint.x - outerPoint.x;
float dy = centerPoint.y - outerPoint.y;
float dd = sqrt(dx*dx + dy*dy);
float a = asinf(radius / dd);
float b = atan2f(dy, dx);
float t1 = b - a;
CGPoint tangentPoint1 = CGPointMake(centerPoint.x + radius*sinf(t1),
centerPoint.y + radius*-cosf(t1));
float t2 = b + a;
CGPoint tangentPoint2 = CGPointMake(centerPoint.x + radius*-sinf(t2),
centerPoint.y + radius*cosf(t2));
NSArray *points = @[
[NSValue valueWithCGPoint:tangentPoint1],
[NSValue valueWithCGPoint:tangentPoint2]
];
return points;
}
Run Code Online (Sandbox Code Playgroud)