简体   繁体   中英

java draw arc tangent to line

I have a line, with a startPoint p1 (x,y) and an endPoint p2 (x,y). I want to draw an arc, with its startPoint being p2, to an 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?

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:

例子2

this image came from w3schools, i'm trying to achieve pretty much the same thing. w3schools url

You have points P1, P2, P3 and vector

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

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

P2C = P2 - C  //really -uP*radius
A2 = atan2(P2C.y, P2C.x)

P3C = P3 - C
A3 = atan2(P3C.y, P3C.x)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM