howord
howord

Reputation: 97

How to find the angle between three points with openlayers?

I use openlayers version 6.5.

I want to find the angle between two lines or three points.

Is there a library to reference or how to get it?

enter image description here

No related library was found. Should I solve it mathematically?

Upvotes: 1

Views: 229

Answers (1)

hopeless-programmer
hopeless-programmer

Reputation: 990

You can use dot product:

The dot product of two normalized vectors is equal to angle between them. In general case when the vectors are not normalized the equation is the following:

cos(a^b) = dot(a,b) / length(a) / length(b)

Thus:

a^b = arccos(dot(a,b) / length(a) / length(b))

Or:

a^b = arccos( (a.x*b.x + a.y*b.y + a.z*b.z) / sqrt(a.x^2+a.y^2+a.z^2) / sqrt(b.x^2+b.y^2+b.z^2) )

Upvotes: 1

Related Questions