/** * For this vertex enclosed in a triangle defined by three vertices v0, v1 and v2, interpolate * a z value from the surrounding vertices. */ public double interpolateZValue(Vertex v0, Vertex v1, Vertex v2) { double x0 = v0.getX(); double y0 = v0.getY(); double a = v1.getX() - x0; double b = v2.getX() - x0; double c = v1.getY() - y0; double d = v2.getY() - y0; double det = a * d - b * c; double dx = this.getX() - x0; double dy = this.getY() - y0; double t = (d * dx - b * dy) / det; double u = (-c * dx + a * dy) / det; double z = v0.getZ() + t * (v1.getZ() - v0.getZ()) + u * (v2.getZ() - v0.getZ()); return z; }
/** * returns a new vertex that is mid-way between this vertex and another end point. * * @param a the other end point. * @return the point mid-way between this and that. */ public Vertex midPoint(Vertex a) { double xm = (p.x + a.getX()) / 2.0; double ym = (p.y + a.getY()) / 2.0; double zm = (p.z + a.getZ()) / 2.0; return new Vertex(xm, ym, zm); }
/** * For this vertex enclosed in a triangle defined by three vertices v0, v1 and v2, interpolate * a z value from the surrounding vertices. */ public double interpolateZValue(Vertex v0, Vertex v1, Vertex v2) { double x0 = v0.getX(); double y0 = v0.getY(); double a = v1.getX() - x0; double b = v2.getX() - x0; double c = v1.getY() - y0; double d = v2.getY() - y0; double det = a * d - b * c; double dx = this.getX() - x0; double dy = this.getY() - y0; double t = (d * dx - b * dy) / det; double u = (-c * dx + a * dy) / det; double z = v0.getZ() + t * (v1.getZ() - v0.getZ()) + u * (v2.getZ() - v0.getZ()); return z; }
/** * returns a new vertex that is mid-way between this vertex and another end point. * * @param a the other end point. * @return the point mid-way between this and that. */ public Vertex midPoint(Vertex a) { double xm = (p.x + a.getX()) / 2.0; double ym = (p.y + a.getY()) / 2.0; double zm = (p.z + a.getZ()) / 2.0; return new Vertex(xm, ym, zm); }
continue; processed.add(e); int cut = cut(e.orig().getZ(), e.dest().getZ(), z0); if (cut == 0) { continue; // While, next edge QuadEdge E1 = ccw ? e.oNext().getPrimary() : e.oPrev().getPrimary(); QuadEdge E2 = ccw ? e.dPrev().getPrimary() : e.dNext().getPrimary(); int cut1 = E1 == null ? 0 : cut(E1.orig().getZ(), E1.dest().getZ(), z0); int cut2 = E2 == null ? 0 : cut(E2.orig().getZ(), E2.dest().getZ(), z0); boolean ok1 = cut1 != 0 && !processed.contains(E1); boolean ok2 = cut2 != 0 && !processed.contains(E2);