/** * Creates a new vector from an existing one. * * @param v the vector to copy * @return a new vector */ public static Vector2D create(Vector2D v) { return new Vector2D(v); }
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); } }
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());
/** * * @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())); } }
/** * 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); }
Vector2D myVector = new Vector2D(50, 50); // instantiated without direction or magnitude Point2D.Double myPoint = new Point2D.Double(myVector.getLocation());
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);
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; } }
/** * * @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())); } }
/** * 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); }
/** * Creates a vector from a {@link Coordinate}. * * @param coord the Coordinate to copy * @return a new vector */ public static Vector2D create(Coordinate coord) { return new Vector2D(coord); }
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); } }
public Vector2D negate() { return create(-x , -y); }