Compute the normal of a triangle.

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
main
sigonasr2, Sig, Sigo 3 years ago
parent 3d9b21923e
commit e0f6a3f225
  1. 3
      src/sig/SigRenderer.java
  2. 11
      src/sig/Triangle.java

@ -17,8 +17,9 @@ public class SigRenderer implements MouseListener,MouseMotionListener{
}
SigRenderer(JFrame f) {
tri = new Triangle(new Vector3d(),new Vector3d(),new Vector3d());
tri = new Triangle(new Vector3d(-1,-1,0),new Vector3d(1,0,0),new Vector3d(0,2,0));
System.out.println(tri);
System.out.println(tri.getNormal());
Panel p = new Panel();

@ -12,4 +12,15 @@ public class Triangle {
public String toString() {
return "Triangle [A=" + A + ", B=" + B + ", C=" + C + "]";
}
public Vector3d getNormal() {
Vector3d AB = (Vector3d)A.clone();
AB.sub(B);
Vector3d BC = (Vector3d)B.clone();
BC.sub(C);
Vector3d crossP = new Vector3d();
crossP.cross(AB,BC);
crossP.normalize();
return crossP;
}
}

Loading…
Cancel
Save