Computational Geometry
The study of geometric problems.
This is not graphics, but uses some of the same ideas.
We will look at collections of points in the plane $p_i=(x_i, y_i)$
Given a set of three points, do you make a right or left hand turn traveling from $p_1$ to $p_3$?
p
1
x:
0
y
0
p
2
x:
0
y
0
p
3
x:
0
y
0
p
1
p
2
× p
2
p
3
:
0
p
1
p
2
· p
2
p
3
:
0
Angle:
Direction:
Turn Type:
This is relatively easy to compute.
It is just the
cross product
$\overrightarrow{p_1p_2} \times \overrightarrow{p_2p_3}$
$\overrightarrow{p_1p_2} \times \overrightarrow{p_2p_3} = (p_1.x - p_2.x)(p_3.y-p_2.y) - (p_3.x-p_2.x)(p_1.y-p_2.y)$
$\overrightarrow{p_1p_2} \times \overrightarrow{p_2p_3} = |\overrightarrow{p_1p_2}||\overrightarrow{p_2p_3}|\sin(\Theta)n$
$|\overrightarrow{p_1p_2}|$ is the length of the line.
$\Theta$ is the angle between the two lines.
$n$ is the normal vector $(0,0,1)$ in this case.
$a \times b = -( b \times a)$
The second interpretation is useful here.
Remember, $\sin$ is positive for values between 0 and 180°
And negative for values between 180° and 360°
Assume $\overrightarrow{p_1p_2}$ is the positive x axis.
$\Theta$ is the angle \overrightarrow{p_2p_3}$ makes with this.
So when the sin is positive, we are in 1/2 of the plane.
A positive sin represents:
Moving counterclockwise from p1 to p3 is the shortest arc.
Driving along $\overrightarrow{p_1p_2}$ we need to turn
right
at $p_2$ to reach $p_3$
A negative sin represents the opposite.
By the way, the
dot
product
$\overrightarrow{p_1p_2} \cdot \overrightarrow{p_2p_3} = (p_1.x - p_2.x)(p_3.x-p_2.x) + (p_1.y-p_2.y)(p_3.y-p_2.y)$
$\overrightarrow{p_1p_2} \cdot \overrightarrow{p_2p_3} = |\overrightarrow{p_1p_2}||\overrightarrow{p_2p_3}|\cos(\Theta)$