private Coordinate displaceFromCorner(Coordinate nearPt, Coordinate p1, Coordinate p2, double dist) { Coordinate[] corner = orientCorner(nearPt, p1, p2); // compute perpendicular bisector of p1-p2 Vector2D u1 = Vector2D.create(nearPt, corner[0]).normalize(); Vector2D u2 = Vector2D.create(nearPt, corner[1]).normalize(); double ang = u1.angle(u2); Vector2D innerBisec = u2.rotate(ang / 2); Vector2D offset = innerBisec.multiply(dist); if (! isInsideCorner(vertexPt, nearPt, corner[0], corner[1])) { offset = offset.multiply(-1); } return offset.translate(vertexPt); }
/** * Creates a vector with the direction and magnitude * of the difference between the * <tt>to</tt> and <tt>from</tt> {@link Coordinate}s. * * @param from the origin Coordinate * @param to the destination Coordinate * @return a new vector */ public static Vector2D create(Coordinate from, Coordinate to) { return new Vector2D(from, to); }
private Coordinate displaceFromFlatCorner(Coordinate nearPt, Coordinate p1, Coordinate p2, double dist) { // compute perpendicular bisector of p1-p2 Vector2D bisecVec = Vector2D.create(p2, p1).rotateByQuarterCircle(1); Vector2D offset = bisecVec.normalize().multiply(dist); return offset.translate(vertexPt); } }
/** * Returns an array of pts such that p0 - p[0] - [p1] is CW. * * @param p0 * @param p1 * @param p2 * @return */ private static Vector2D normalizedOffset(Coordinate p0, Coordinate p1, Coordinate p2) { Vector2D u1 = Vector2D.create(p0, p1).normalize(); Vector2D u2 = Vector2D.create(p0, p2).normalize(); Vector2D offset = u1.add(u2).normalize(); return offset; }
private LineString voronoiSide(int idgeom, int side,GeometryFactory geometryFactory, Coordinate circumcenter) { boolean triangleCCW = isCCW(idgeom); // Create linestring to envelope LineSegment sideGeom = getTriangleSegment(idgeom, side); Vector2D direction = new Vector2D(sideGeom.p0, sideGeom.p1); direction = direction.normalize().rotate(triangleCCW ? - Math.PI / 2 : Math.PI / 2).multiply(envelope.maxExtent()); LineSegment voronoiLine = new LineSegment(circumcenter, new Coordinate(direction.getX() + circumcenter.x, direction.getY() + circumcenter.y)); Geometry lineString = voronoiLine.toGeometry(geometryFactory).intersection(geometryFactory.toGeometry(envelope)); if(lineString instanceof LineString && lineString.getLength() > epsilon) { return (LineString)lineString; } else { return null; } }
Vector2D vStart = new Vector2D(startCoordinate); double angleRad = elementaryAngle * i; Vector2D v = Vector2D.create(Math.cos(angleRad), Math.sin(angleRad)); v = v.multiply(stepLength); double max = 0; for (int j = 0; j < stepCount; j++) { LineSegment stepLine = new LineSegment(vStart.add(v.multiply(j)).toCoordinate(), vStart.add(v.multiply(j + 1)).toCoordinate()); LineString rayStep = stepLine.toGeometry(factory); List<LineString> interEnv = sTRtree.query(rayStep.getEnvelopeInternal());
/** * Multiplies the vector by a scalar value. * * @param d the value to multiply by * @return a new vector with the value v * d */ public Vector2D multiply(double d) { return create(x * d, y * d); }
private Coordinate displaceFromCornerOriginal(Coordinate nearPt, Coordinate p1, Coordinate p2, double dist) { // if corner is nearly flat, just displace point // TODO: displace from vertex on appropriate side of flat line, with suitable angle if (isFlat(nearPt, p1, p2)) return displaceFromFlatCorner(nearPt, p1, p2, dist); Coordinate[] corner = orientCorner(nearPt, p1, p2); // find quadrant of corner that vertex pt lies in int quadrant = quadrant(vertexPt, nearPt, corner); Vector2D normOffset = normalizedOffset(nearPt, p1, p2); Vector2D baseOffset = normOffset.multiply(dist); Vector2D rotatedOffset = baseOffset.rotateByQuarterCircle(quadrant); return rotatedOffset.translate(vertexPt); //return null; }
public void testToCoordinate() { assertEquals(Vector2D.create( Vector2D.create(1,2).toCoordinate()), Vector2D.create(1,2), TOLERANCE); }
/** * * @param normal Plane normal * @param epsilon Epsilon value ex:1e-12 * @return The steepest slope of this plane in degree. */ public static double getSlopeInPercent(final Vector3D normal, final double epsilon) { Vector3D vector = getSteepestVector(normal, epsilon); if(Math.abs(vector.getZ()) < epsilon) { return 0; } else { return (Math.abs(vector.getZ()) / new Vector2D(vector.getX(), vector.getY()).length()) * 100; } }
/** * Compute the aspect in degree. The geometry must be a triangle. * @param geometry Polygon triangle * @return aspect in degree * @throws IllegalArgumentException ST_TriangleAspect accept only triangles */ public static Double computeAspect(Geometry geometry) throws IllegalArgumentException { if (geometry == null) { return null; } Vector3D vector = TriMarkers.getSteepestVector(TriMarkers.getNormalVector(TINFeatureFactory.createTriangle(geometry)), TINFeatureFactory.EPSILON); if (vector.length() < TINFeatureFactory.EPSILON) { return 0d; } else { Vector2D v = new Vector2D(vector.getX(), vector.getY()); return measureFromNorth(Math.toDegrees(v.angle())); } }
public void testIsParallel() throws Exception { assertTrue(Vector2D.create(0,1).isParallel(Vector2D.create(0,2))); assertTrue(Vector2D.create(1,1).isParallel(Vector2D.create(2,2))); assertTrue(Vector2D.create(-1,-1).isParallel(Vector2D.create(2,2))); assertTrue(! Vector2D.create(1,-1).isParallel(Vector2D.create(2,2))); }
Vector2D v0 = new Vector2D(t.p0.x - t.p2.x, t.p0.y - t.p2.y); Vector2D v1 = new Vector2D(t.p1.x - t.p2.x, t.p1.y - t.p2.y); Vector2D v2 = new Vector2D(p.x - t.p2.x, p.y - t.p2.y); double dot00 = v0.dot(v0); double dot01 = v0.dot(v1); double dot02 = v0.dot(v2); double dot11 = v1.dot(v1); double dot12 = v1.dot(v2);
public void addSide(int level, Coordinate p0, Coordinate p1) { if (level == 0) addSegment(p0, p1); else { Vector2D base = Vector2D.create(p0, p1); Coordinate midPt = base.multiply(0.5).translate(p0); Vector2D heightVec = base.multiply(THIRD_HEIGHT); Vector2D offsetVec = heightVec.rotateByQuarterCircle(1); Coordinate offsetPt = offsetVec.translate(midPt); int n2 = level - 1; Coordinate thirdPt = base.multiply(ONE_THIRD).translate(p0); Coordinate twoThirdPt = base.multiply(TWO_THIRDS).translate(p0); // construct sides recursively addSide(n2, p0, thirdPt); addSide(n2, thirdPt, offsetPt); addSide(n2, offsetPt, twoThirdPt); addSide(n2, twoThirdPt, p1); } }
/** * Divides the vector by a scalar value. * * @param d the value to divide by * @return a new vector with the value v / d */ public Vector2D divide(double d) { return create(x / d, y / d); }