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 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; } }
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 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());