### Tags: angle, form, matlab, points, pointsangle, programming

# angle between three points (x1,y1,z1),(x2,y2,z2),(x3,y3,z3)

On Programmer » Matlab

2,051 words with 2 Comments; publish: Sun, 18 May 2008 21:47:00 GMT; (20062.50, « »)

hello..

I need some help to get this angle form these three points

angle between three points (x1,y1,z1),(x2,y2,z2),(x3,y3,z3)..

*http://matlab.todaysummary.com/q_matlab_3257.html*

All Comments

Leave a comment...

- 2 Comments
- pra mvd wrote:
>

> hello..

> I need some help to get this angle form these three points

> angle between three points (x1,y1,z1),(x2,y2,z2),(x3,y3,z3)..

Since you didn't say which of the three angles you want we'll do all

three.

Start by letting (x1, y1, z1) be the center point, then the two line

segments are:

v2 = (x2-x1, y2-y1, z2-z1)

v3 = (x3-x1, y3-y1, z3-z1)

Normalize the two vectors:

u2 = v2 / norm(v2)

u3 = v3 / norm(v3)

The angle is then theta1 = acos( dot(u2, u3) ) in radians

Now let (x2, y2, z2) be the center point , then the two line segments

are:

v1 = -(x2-x1, y2-y1, z2-z1)

v3 = (x3-x2, y3-y2, z3-z2)

Normalize the two vectors:

u1 = v1 / norm(v1)

u3 = v3 / norm(v3)

The angle is then theta2 = acos( dot(u1, u3) ) in radians

Finally theta3 = pi - theta1 - theta2

#1; Sun, 18 May 2008 21:48:00 GMT

- pra mvd wrote:
- In article <ef56cfd.-1.matlab.todaysummary.com.webcrossing.raydaftYaTP>, "pra mvd"
<praschoudary.matlab.todaysummary.com.yahoo.com> wrote:

> hello..

> I need some help to get this angle form these three points

> angle between three points (x1,y1,z1),(x2,y2,z2),(x3,y3,z3)..

--

Call the three points A = (x1,y1,z1), B = (x2,y2,z2), and C =

(x3,y3,z3). I am assuming you want angle ABC, the angle between vector BA

and vector BC. This angle can best be evaluated using matlab's 'atan2'

function.

v21 = [x1-x2,y1-y2,z1-z2]; % Vector from B to A

v23 = [x3-x2,y3-y2,z3-z2]; % Vector from B to C

angle = atan2(norm(cross(v21,v23)),dot(v21,v23))

;

The value of 'angle' can range anywhere from 0 to +pi radians.

Roger Stafford

#2; Sun, 18 May 2008 21:49:00 GMT

- In article <ef56cfd.-1.matlab.todaysummary.com.webcrossing.raydaftYaTP>, "pra mvd"