[英]java draw arc tangent to line
I have a line, with a startPoint
p1 (x,y) and an endPoint
p2 (x,y).我有一条线,有一个
startPoint
p1 (x,y) 和一个endPoint
p2 (x,y)。 I want to draw an arc, with its startPoint
being p2, to an endPoint
p3 (x,y).我想绘制一条弧,其
startPoint
为 p2,到endPoint
p3 (x,y)。 the radius of the circle of which the arc is a part of is known.圆弧所属的圆的半径是已知的。 What I'm trying to achieve:
我正在努力实现的目标:
in the picture above, ignore the letters.在上图中,忽略字母。 I took this image from google images.
我从谷歌图片中获取了这张图片。
How can i draw an arc with know radius
r, startPoint
(end point of line L) and endPoint
, tangent
to line L?我怎样才能画一条已知
radius
r、 startPoint
(线 L 的终点)和endPoint
, tangent
线 L tangent
?
edit:编辑:
I know how to draw an arc, I just don't know how to draw an arc tangent to the endpoint of the line.我知道如何画圆弧,只是不知道如何画与线端点相切的圆弧。
update: I found another perfect example picture:更新:我找到了另一个完美的示例图片:
this image came from w3schools, i'm trying to achieve pretty much the same thing.这张图片来自 w3schools,我正在努力实现几乎相同的目标。 w3schools url
w3schools 网址
You have points P1, P2, P3 and vector你有点 P1、P2、P3 和向量
D = P2 - P1 //(x2-x1, y2-y1)
get unit vector获取单位向量
uD = D / Length(D)
and perpendicular unit vector和垂直单位向量
uP = (-uD.y, uD.x)
Check needed direction of perpendicular检查所需的垂直方向
dp = uP.dot.(x3-x1, y3-y1)
if dp is negative, negate uP vector to provide correct position of the circle center如果 dp 为负,则取反 uP 向量以提供圆心的正确位置
Then find circle center然后找到圆心
C = P2 + uP * Radius
If you need starting and ending angles to form an arc, calculate them using atan2 (ArcTan2) function如果您需要开始和结束角度来形成圆弧,请使用 atan2 (ArcTan2) 函数计算它们
P2C = P2 - C //really -uP*radius
A2 = atan2(P2C.y, P2C.x)
P3C = P3 - C
A3 = atan2(P3C.y, P3C.x)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.