ok, quickly...
use PVector.cross() to give you the normal
A--B
| |
C--D
A = (0, 0, 0);
B = (300, 0, 0);
C = (0, 450, 0);
D = (300, 450, 0);
choose two vectors, A to C and C to D. those work out as (0 - 0, 450 - 0, 0 - 0) and (300 - 0, 450 - 450, 0 - 0)
ie (0, 450, 0) and (300, 0, 0), which, crossed, gives (0, 0, -135), pointing along the -ve z-axis which is a vector perpendicular to the first two.
for the other side choose A to D and D to C. (300 - 0, 450 - 0, 0 - 0) and (0 - 300, 450 - 450, 0 - 0)
(300, 450, 0) crossed with (-300, 0, 0) gives (0, 0, 135), ie along +ve z-axis.
that these two vectors have opposite signs indicates they are facing away from each other.
IT IS IMPORTANT to consistently number the edges in order for this to work. A - C - D is anticlockwise looking from the front, A - D - C is anti-clockwise when looking from the back. mixing clockwise orderings and anti-clockwise orderings will mean this doesn't work.
- PVector pA = new PVector(0, 0, 0);
- PVector pB = new PVector(300, 0, 0);
- PVector pC = new PVector(0, 450, 0);
- PVector pD = new PVector(300, 450, 0);
- PVector pAC = PVector.sub(pC, pA); // A to C
- PVector pCD = PVector.sub(pD, pC); // C to D
- PVector c1 = pAC.cross(pCD);
- println(c1.x + " " + c1.y + " " + c1.z);
- PVector pAD = PVector.sub(pD, pA); // A to D
- PVector pDC = PVector.sub(pC, pD); // D to C
- PVector c2 = pAD.cross(pDC);
- println(c2.x + " " + c2.y + " " + c2.z);