質問

I work in canvas and I want to draw some lines.

I have a first line defined by 2 points P1 (x1,y1) and P2 (x2,y2). I know how to calculate distance r between these 2 points with formula : sqrt((x2-x1)^2 + (y2-y1)^2) .

My problem is the following. With a defined angle Alpha, I would like to calculate coords of a point P3 (x3,y3) like distances P1P3 = P1P2 = r.

I guess it's a problem with trigonometry or polar coords perhaps but I don't remember these notions and I have some problems to find the solution.

The following image resumes the post and show a representation :

How to calculate P3 coords

Someone has some ideas about the solution ?

Thanks by advance for your help.

Sylvain

役に立ちましたか?

解決

The basic idea is to rotate the difference vector:

dx := x2 - x1
dy := y2 - y1

dx' := cos alpha * dx - sin alpha * dy
dy' := sin alpha * dx + cos alpha * dy

x3 := x1 + dx'
y3 := x1 + dy'
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top