package cse1030; /** * A simple triangle class where a Triangle is an composition of three Point * objects. * * @author CSE1030 * */ public class TriangleC { private Point pA; private Point pB; private Point pC; private Point normal; // this should really be some sort of vector... public TriangleC() { // constructor chaining will create unnecessary objects this.pA = new Point(0., 0., 0.); this.pB = new Point(0., 1., 0.); this.pC = new Point(1., 0., 0.); } public TriangleC(Point a, Point b, Point c) { this.pA = new Point(a); this.pB = new Point(b); this.pC = new Point(c); this.calcNormal(); } public TriangleC(TriangleC other) { // constructor chaining will create unnecessary objects this.pA = other.getA(); this.pB = other.getB(); this.pC = other.getC(); this.normal = other.getNormal(); } private final void calcNormal() { double ux = this.pB.getX() - this.pA.getX(); double uy = this.pB.getY() - this.pA.getY(); double uz = this.pB.getZ() - this.pA.getZ(); double vx = this.pC.getX() - this.pA.getX(); double vy = this.pC.getY() - this.pA.getY(); double vz = this.pC.getZ() - this.pA.getZ(); double nx = uy * vz - uz * vy; double ny = uz * vx - ux * vz; double nz = ux * vy - uy * vx; double mag = Math.sqrt(nx * nx + ny * ny + nz * nz); nx /= mag; ny /= mag; nz /= mag; this.normal = new Point(nx, ny, nz); } public Point getA() { return new Point(this.pA); } public void setA(Point a) { Point copy = new Point(a); // validate? this.pA = copy; } public Point getB() { return new Point(this.pB); } public void setB(Point b) { Point copy = new Point(b); // validate? this.pB = copy; } public Point getC() { return new Point(this.pC); } public void setC(Point c) { Point copy = new Point(c); // validate? this.pC = copy; } public Point getNormal() { return new Point(this.normal); } }