import java.awt.*; import java.util.*; public class Surface extends Polygon { Vector vertices = new Vector(); float center; boolean selected = true; String url; String text = new String(); Polygon stereoPair = new Polygon(); Color color; Color shade; public Surface() { } public Surface(Color color) { this.color = color; } void colorAndShade(float x0, float y0, float z0) { if(npoints > 2) { Vertex vertex1 = (Vertex)vertices.elementAt(0); Vertex vertex2 = (Vertex)vertices.elementAt(1); Vertex vertex3 = (Vertex)vertices.elementAt(2); float x1 = vertex2.coordinate[0]-vertex1.coordinate[0]; float y1 = vertex2.coordinate[1]-vertex1.coordinate[1]; float z1 = vertex2.coordinate[2]-vertex1.coordinate[2]; float x2 = vertex3.coordinate[0]-vertex1.coordinate[0]; float y2 = vertex3.coordinate[1]-vertex1.coordinate[1]; float z2 = vertex3.coordinate[2]-vertex1.coordinate[2]; float r0 = (float)Math.sqrt(x0*x0+y0*y0+z0*z0); float r1 = (float)Math.sqrt(x1*x1+y1*y1+z1*z1); float r2 = (float)Math.sqrt(x2*x2+y2*y2+z2*z2); float angle = (float)Math.sqrt((1+(x0*(y1*z2-y2*z1)-y0*(x1*z2-x2*z1)+z0*(x1*y2-x2*y1))/(r0*r1*r2)*(x1*y2-x2*y1)/(r1*r2))/2); shade = new Color((int)(color.getRed()*angle),(int)(color.getGreen()*angle),(int)(color.getBlue()*angle)); } else { shade = color; } } void setSelected(boolean selected) { this.selected = selected; } boolean getSelected() { return selected; } public void addVertex(Vertex vertex) { vertices.addElement(vertex); super.addPoint(0,0); stereoPair.addPoint(0,0); } public void setHttp(String url, String text) { this.url = url; this.text = text; } public String getURL() { return url; } public String getText() { return text; } public void render(float x, float y, float scale) { for(int j = 0; j < npoints; j++) { Vertex currentVertex = (Vertex)vertices.elementAt(j); xpoints[j] = (int)(currentVertex.coordinate[0]*scale+x); ypoints[j] = (int)(currentVertex.coordinate[1]*scale+y); } } public void renderStereo(float x, float y, float scale, float nosy) { for(int j = 0; j < npoints; j++) { Vertex currentVertex = (Vertex)vertices.elementAt(j); xpoints[j] = (int)((currentVertex.coordinate[0]*scale+60.0)*nosy/(nosy-currentVertex.coordinate[2]*scale)-60.0+x); ypoints[j] = (int)(currentVertex.coordinate[1]*scale*nosy/(nosy-currentVertex.coordinate[2]*scale)+y); stereoPair.xpoints[j] = (int)((currentVertex.coordinate[0]*scale-60.0)*nosy/(nosy-currentVertex.coordinate[2]*scale)+60.0+x); stereoPair.ypoints[j] = (int)(currentVertex.coordinate[1]*scale*nosy/(nosy-currentVertex.coordinate[2]*scale)+y); } } public void renderPolar(float x, float y, float scale, float nosy) { for(int j = 0; j < npoints; j++) { Vertex currentVertex = (Vertex)vertices.elementAt(j); xpoints[j] = (int)((currentVertex.coordinate[0]*scale+60.0)*nosy/(nosy-currentVertex.coordinate[2]*scale)-60.0+x-x/2); ypoints[j] = (int)(currentVertex.coordinate[1]*scale*nosy/(nosy-currentVertex.coordinate[2]*scale)+y); stereoPair.xpoints[j] = (int)((currentVertex.coordinate[0]*scale-60.0)*nosy/(nosy-currentVertex.coordinate[2]*scale)+60.0+x+x/2); stereoPair.ypoints[j] = (int)(currentVertex.coordinate[1]*scale*nosy/(nosy-currentVertex.coordinate[2]*scale)+y); } } public void calculateCenter() { center = 0; for(int j = 0; j < npoints; j++) { Vertex currentVertex = (Vertex)vertices.elementAt(j); center += currentVertex.coordinate[2]/npoints; } } }