this.coordinates.put(v.getCoordinate(), iV); this.vertices.put(iV, new Vertex(iV, v.getCoordinate())); iV++;
public int classify(Vertex p0, Vertex p1) { Vertex p2 = this; Vertex a = p1.sub(p0); Vertex b = p2.sub(p0); double sa = a.crossProduct(b); if (sa > 0.0) return LEFT; if (sa < 0.0) return RIGHT; if ((a.getX() * b.getX() < 0.0) || (a.getY() * b.getY() < 0.0)) return BEHIND; if (a.magn() < b.magn()) return BEYOND; if (p0.equals(p2)) return ORIGIN; if (p1.equals(p2)) return DESTINATION; return BETWEEN; }
/** * 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); }
public void visit(QuadEdge[] triEdges) { Coordinate a = triEdges[0].orig().getCoordinate(); Coordinate b = triEdges[1].orig().getCoordinate(); Coordinate c = triEdges[2].orig().getCoordinate(); // TODO: choose the most accurate circumcentre based on the edges Coordinate cc = Triangle.circumcentre(a, b, c); Vertex ccVertex = new Vertex(cc); // save the circumcentre as the origin for the dual edges originating in this triangle for (int i = 0; i < 3; i++) { triEdges[i].rot().setOrig(ccVertex); } } }
/** * Computes the centre of the circumcircle of this vertex and two others. * * @param b * @param c * @return the Coordinate which is the circumcircle of the 3 points. */ public Vertex circleCenter(Vertex b, Vertex c) { Vertex a = new Vertex(this.getX(), this.getY()); // compute the perpendicular bisector of cord ab HCoordinate cab = bisector(a, b); // compute the perpendicular bisector of cord bc HCoordinate cbc = bisector(b, c); // compute the intersection of the bisectors (circle radii) HCoordinate hcc = new HCoordinate(cab, cbc); Vertex cc = null; try { cc = new Vertex(hcc.getX(), hcc.getY()); } catch (NotRepresentableException nre) { System.err.println("a: " + a + " b: " + b + " c: " + c); System.err.println(nre); } return cc; }
/** * 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; }
else if (subdiv.isOnEdge(e, v.getCoordinate())) { if (t.dest().rightOf(e) && v.isInCircle(e.orig(), t.dest(), e.dest())) { QuadEdge.swap(e); e = e.oPrev();
continue; processed.add(e); int cut = cut(e.orig().getZ(), e.dest().getZ(), z0); if (cut == 0) { continue; // While, next edge cC = moveEpsilonTowards(e.dest().getCoordinate(), e.orig().getCoordinate()); } else if (triangulation.isFrameVertex(e.dest())) { cC = moveEpsilonTowards(e.orig().getCoordinate(), e.dest().getCoordinate()); } else { cC = e.orig().midPoint(e.dest()).getCoordinate(); 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);
/** * Tests whether a vertex is a vertex of the outer triangle. * * @param v * the vertex to test * @return true if the vertex is an outer triangle vertex */ public boolean isFrameVertex(Vertex v) { if (v.equals(frameVertex[0])) return true; if (v.equals(frameVertex[1])) return true; if (v.equals(frameVertex[2])) return true; return false; }
/** * Computes the scalar product c(v) * * @param v a vertex * @return returns the scaled vector */ Vertex times(double c) { return (new Vertex(c * p.x, c * p.y)); }
private void createFrame(Envelope env) { double deltaX = env.getWidth(); double deltaY = env.getHeight(); double offset = 0.0; if (deltaX > deltaY) { offset = deltaX * 10.0; } else { offset = deltaY * 10.0; } frameVertex[0] = new Vertex((env.getMaxX() + env.getMinX()) / 2.0, env .getMaxY() + offset); frameVertex[1] = new Vertex(env.getMinX() - offset, env.getMinY() - offset); frameVertex[2] = new Vertex(env.getMaxX() + offset, env.getMinY() - offset); frameEnv = new Envelope(frameVertex[0].getCoordinate(), frameVertex[1] .getCoordinate()); frameEnv.expandToInclude(frameVertex[2].getCoordinate()); }
/** * 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); }
/** * Computes the centre of the circumcircle of this vertex and two others. * * @param b * @param c * @return the Coordinate which is the circumcircle of the 3 points. */ public Vertex circleCenter(Vertex b, Vertex c) { Vertex a = new Vertex(this.getX(), this.getY()); // compute the perpendicular bisector of cord ab HCoordinate cab = bisector(a, b); // compute the perpendicular bisector of cord bc HCoordinate cbc = bisector(b, c); // compute the intersection of the bisectors (circle radii) HCoordinate hcc = new HCoordinate(cab, cbc); Vertex cc = null; try { cc = new Vertex(hcc.getX(), hcc.getY()); } catch (NotRepresentableException nre) { System.err.println("a: " + a + " b: " + b + " c: " + c); System.err.println(nre); } return cc; }
/** * 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; }
/** * Tests whether a {@link Vertex} is the start or end vertex of a * {@link QuadEdge}, up to the subdivision tolerance distance. * * @param e * @param v * @return true if the vertex is a endpoint of the edge */ public boolean isVertexOfEdge(QuadEdge e, Vertex v) { if ((v.equals(e.orig(), tolerance)) || (v.equals(e.dest(), tolerance))) { return true; } return false; }