| 1. |
Take two arbitrary legs from the triangle and express them as vectors. |
|
Let us choose leg1 from P0 to P1: V1=P1-P0= { 0.7-0.0,-0.7-0.0, 0.0-1.0 } = { 0.7,-0.7,-1.0 }. |
|
Let us choose leg2 from P1 to P2: V2=P2-P1= { 0.7-0.7, 0.7+0.7, 0.0-0.0 } = { 0.0, 1.4, 0.0 }. |
| 2. |
Compute the vector product VP = V1 x V2 defined as: |
|
VPx=V1y*V2z - V2y*V1z = (-0.7)*(+0.0) - (+1.4)*(-1.0) = +1.4 |
|
VPy=V1z*V2x - V2z*V1x = (+0.0)*(+0.7) - (+0.0)*(+0.7) = +0.0 |
|
VPz=V1x*V2y - V2x*V1y = (+0.7)*(+1.4) - (+0.0)*(-0.7) = +0.98 |
| 3. |
Correct the orientation of VP if necessary: It must point toward the outside = outer surface of the octahedron. If VP points to the wrong (opposite) direction, OpenGL will probably show us an empty triangular hole instead of a triangular surface covered by a texture. |
|
The easiest test is the scalar product SPtest of VP with an arbitrary vector Vtest pointing into the center of the octahedron. |
|
Let us choose the vector from P0 to { 0,0,0 } as Vtest = { 0,0,0 } - P0 = { 0.0, 0.0, -1.0 }. |
|
SPtest = VP * Vtest = 1.4*0.0 + 0.0*0.0 +0.98*(-1.0) = -0.98. |
|
Everything is OK if SPtest is negative, otherwise VPx, VPy and VPz must be multplied by -1.0. |
| 4. |
Normalize VP to the normal length of 1.0. |
|
The length of VP is sqrt(1.4*1.4 + 0.0*0.0 + 0.98*0.98) = 1.7089. |
|
We have to divide VPx, VPy, VPz by this length in order to obtain the final normal vector N = { 1.4/1.7089, 0.0, 0.98/1.7089 } = {0.8192, 0.0, 0.5735 } |
Because of the symmetry of the octahedron, all other 7 normals are composed of the same 3 values