// a point class Point { float x=0, y=0, z=0; int pcolor=255; int[] rgb = new int[3]; boolean isRGB; String txtID="txt"; int focus=PLAN; Line on_line_1, on_line_2; Line on_lineZ_1, on_lineZ_2; Point[] children; // *** constructors *** Point() {} Point(float xc) { x = xc; } Point(float xc, float yc) { x = xc; y = yc; } Point(float xc, float yc, String id) { x = xc; y = yc; txtID = id; } Point( float xc, float yc, float zc ) { x = xc; y = yc; z = zc; } Point( float xc, float yc, float zc, String id ) { x = xc; y = yc; z = zc; txtID = id; } // *** accessors *** public void X(float xc) { x = xc; NotifyChildren(); } public void Y(float yc) { y = yc; NotifyChildren(); } public void Z(float zc) { z = zc; NotifyChildren(); } public void setColor(int c) { isRGB = false; pcolor = c; } public void setColor(int r, int g, int b) { isRGB = true; rgb[0] = r; rgb[1] = g; rgb[2] = b; } // *** methods *** public void drawPoint() { if (isRGB) { fill(rgb[0], rgb[1], rgb[2]); } else { fill(pcolor); } noStroke(); rect(x, y, 4, 4); rect(x, z, 4, 4); } public void onLines(Line l1, Line l2) { on_line_1 = l1; on_line_2 = l2; } public void onLinesZ(Line l1, Line l2) { on_lineZ_1 = l1; on_lineZ_2 = l2; } // event handlers void NotifyChildren() { if (children.length == 0) {return;} for (int i=0; i centroid.getDist(temp_2)) ? temp_1 : temp_2 ); } // mirror point across line void mirror(Point p) { getSlopeY(); float y_i = p.y - (-1/slope_y) * p.x; Line perp = new Line(p, new Point(0,y_i)); Point mpoint = new Point(getIntersect(perp), getY(getIntersect(perp))); p.x = p.x + 2 * (mpoint.x - p.x); p.y = p.y + 2 * (mpoint.y - p.y); } } // regulating lines class RLine extends Line { boolean isRGB = false; int lcolor = 125; RLine(Point s, Point e) { super(s, e); setColor(125); } RLine(Point s, Point e, int pl) { super(s, e, pl); setColor(125); } } // a horizontal line class HLine extends Line { float height; HLine(float ypos) { super(new Point(0.0, ypos), new Point(width, ypos)); height = ypos; } } // baseline == has moveable endpoints class BLine extends Line { BLine(Point s, Point e) { super(s, e); s.setColor(0,155,0); e.setColor(0,155,0); } public void drawLine() { if (isRGB) { stroke(rgb[0],rgb[1],rgb[2]); } else { stroke(lcolor); } noFill(); line(start.x, start.y, end.x, end.y); start.drawPoint(); end.drawPoint(); } Point unfoldPt(Point p, Point pivot) { // first rotate down to elevation baseline float d = p.getDistZ(pivot); Point p_pri = new Point(pivot.x+d, p.y, 0); // next construct line perp to axis through pivot getSlopeY(); float y_i = p.y - (-1/slope_y)*p.x; Line perp = new Line(p, new Point(0,y_i)); perp.start = new Point(width, perp.getY(width)); //perp.setColor(50); //perp.drawLine(); // now find intersect of arc with center at pivot and through p_pri and line perp d = pivot.getDist(p_pri); // radius perp.getSlopeY(); perp.getYInt(); float x_1 = (-(2*perp.slope_y*(perp.y_int - pivot.y) - 2*pivot.x) + sqrt( sq(2*perp.slope_y*(perp.y_int - pivot.y) - 2*pivot.x) - 4*(sq(perp.slope_y) + 1) * (sq(pivot.x) + sq(perp.y_int - pivot.y) - d*d) )) / (2 * sq(perp.slope_y) + 2); float x_2 = (-(2*perp.slope_y*(perp.y_int - pivot.y) - 2*pivot.x) - sqrt( sq(2*perp.slope_y*(perp.y_int - pivot.y) - 2*pivot.x) - 4*(sq(perp.slope_y) + 1) * (sq(pivot.x) + sq(perp.y_int - pivot.y) - d*d) )) / (2 * sq(perp.slope_y) + 2); Point temp_1 = new Point(x_1, perp.getY(x_1), 0); Point temp_2 = new Point(x_2, perp.getY(x_2), 0); return ( (p_pri.getDist(temp_1) < p_pri.getDist(temp_2)) ? temp_1 : temp_2 ); } }