public static double angleBetween(LineString l1, LineString l2, double tol) { LineSegment ls1 = new LineSegment( l1.getCoordinateN(l1.getNumPoints() - 2), l1.getCoordinateN(l1.getNumPoints() - 1)); LineSegment ls2 = new LineSegment(l2.getCoordinateN(0), l2.getCoordinateN(1)); return (angleBetween(ls1, ls2, tol)); }
protected LineSegment alterLine(LineSegment line, Node n1, Node n2) { Coordinate c1added = ((Coordinate) n1.getObject()); Coordinate c2added = ((Coordinate) n2.getObject()); if (!c1added.equals2D(line.p0) || c2added.equals2D(line.p1)) { return new LineSegment(c1added, c2added); } return line; }
public Graphable remove(Object obj) { LineString ls = (LineString) obj; // parent ecpexts a line segment return (super.remove( new LineSegment(ls.getCoordinateN(0), ls.getCoordinateN(ls.getNumPoints() - 1)))); }
public Graphable get(Object obj) { LineString ls = (LineString) obj; // parent ecpexts a line segment return (super.get( new LineSegment(ls.getCoordinateN(0), ls.getCoordinateN(ls.getNumPoints() - 1)))); }
public static double angleBetween(LineSegment l1, LineSegment l2, double tol) { // analyze slopes // TODO straight vertical lines double s1 = (l1.p1.y - l1.p0.y) / (l1.p1.x - l1.p0.x); double s2 = (l2.p1.y - l2.p0.y) / (l2.p1.x - l2.p0.x); if (Math.abs(s1 - s2) < tol) return (0); if (Math.abs(s1 + s2) < tol) return (Math.PI); // not of equal slope, transform lines so that they are tail to tip and // use the cosine law to calculate angle between // transform line segments tail to tail, originating at (0,0) LineSegment tls1 = new LineSegment( new Coordinate(0, 0), new Coordinate(l1.p1.x - l1.p0.x, l1.p1.y - l1.p0.y)); LineSegment tls2 = new LineSegment( new Coordinate(0, 0), new Coordinate(l2.p1.x - l2.p0.x, l2.p1.y - l2.p0.y)); // line segment for third side of triangle LineSegment ls3 = new LineSegment(tls1.p1, tls2.p1); double c = ls3.getLength(); double a = tls1.getLength(); double b = tls2.getLength(); return (Math.acos((a * a + b * b - c * c) / (2 * a * b))); }
(Edge) super.add( new LineSegment( ls.getCoordinateN(0), ls.getCoordinateN(ls.getNumPoints() - 1)));
int i = 0; while (i + 2 < c.length) { LineSegment ls1 = new LineSegment(c[i], c[i + 1]); LineSegment ls2 = new LineSegment(c[i + 1], c[i + 2]); double a1 = ls1.angle(); double a2 = ls2.angle();
protected LineSegment alterLine(LineSegment line, Node n1, Node n2) { Point c1added = ((Point) n1.getObject()); Point c2added = ((Point) n2.getObject()); if (!c1added.getCoordinate().equals(line.p0) || c2added.getCoordinate().equals(line.p1)) { line = new LineSegment(c1added.getCoordinate(), c2added.getCoordinate()); } return line; }
/** * Creates a new instance for the given points. * * @param p0 the start point * @param p1 the end point */ public Segment(Coordinate p0, Coordinate p1) { ls = new LineSegment(p0, p1); }
public DepthSegment(LineSegment seg, int depth) { // input seg is assumed to be normalized upwardSeg = new LineSegment(seg); //upwardSeg.normalize(); this.leftDepth = depth; } /**
private Coordinate displaceFromPoint(Coordinate nearPt, double dist) { LineSegment seg = new LineSegment(nearPt, vertexPt); // compute an adjustment which displaces in the direction of the nearPt-vertexPt vector // TODO: make this robust! double len = seg.getLength(); double frac = (dist + len) / len; Coordinate strPt = seg.pointAlong(frac); return strPt; }
private void updatePts(Coordinate p, Coordinate seg0, Coordinate seg1) { minPts[0] = p; LineSegment seg = new LineSegment(seg0, seg1); minPts[1] = new Coordinate(seg.closestPoint(p)); }
/** * Creates a {@link LineSegment} representing the * geometry of this edge. * * @return a LineSegment */ public LineSegment toLineSegment() { return new LineSegment(vertex.getCoordinate(), dest().getCoordinate()); }
private void updateClearance(double candidateValue, Coordinate p, Coordinate seg0, Coordinate seg1) { if (candidateValue < minClearance) { minClearance = candidateValue; minClearancePts[0] = new Coordinate(p); LineSegment seg = new LineSegment(seg0, seg1); minClearancePts[1] = new Coordinate(seg.closestPoint(p)); } }
private void updateNearestLocationsLineLine(int i, Coordinate p0, Coordinate p1, FacetSequence facetSeq, int j, Coordinate q0, Coordinate q1, GeometryLocation[] locs) { LineSegment seg0 = new LineSegment(p0, p1); LineSegment seg1 = new LineSegment(q0, q1); Coordinate[] closestPt = seg0.closestPoints(seg1); locs[0] = new GeometryLocation(geom, i, new Coordinate(closestPt[0])); locs[1] = new GeometryLocation(facetSeq.geom, j, new Coordinate(closestPt[1])); }
public static void computeDistance(LineString line, Coordinate pt, PointPairDistance ptDist) { LineSegment tempSegment = new LineSegment(); Coordinate[] coords = line.getCoordinates(); for (int i = 0; i < coords.length - 1; i++) { tempSegment.setCoordinates(coords[i], coords[i + 1]); // this is somewhat inefficient - could do better Coordinate closestPt = tempSegment.closestPoint(pt); ptDist.setMinimum(closestPt, pt); } }
private Coordinate[] generateSegmentCurve(Coordinate p0, Coordinate p1, double width0, double width1) { LineSegment seg = new LineSegment(p0, p1); double dist0 = width0 / 2; double dist1 = width1 / 2; Coordinate s0 = seg.pointAlongOffset(0, dist0); Coordinate s1 = seg.pointAlongOffset(1, dist1); Coordinate s2 = seg.pointAlongOffset(1, -dist1); Coordinate s3 = seg.pointAlongOffset(0, -dist0); Coordinate[] pts = new Coordinate[] { s0, s1, s2, s3, s0 }; return pts; }
LineSegment segment = new LineSegment(o1, o2); double d1 = segment.distance(c1); double d2 = segment.distance(c2);
void checkOrientationIndex(LineSegment seg, double s0x, double s0y, double s1x, double s1y, int expectedOrient) { LineSegment seg2 = new LineSegment(s0x, s0y, s1x, s1y); int orient = seg.orientationIndex(seg2); assertTrue(orient == expectedOrient); }
private void updateNearestLocationsPointLine(Coordinate pt, FacetSequence facetSeq, int i, Coordinate q0, Coordinate q1, GeometryLocation[] locs) { locs[0] = new GeometryLocation(geom, start, new Coordinate(pt)); LineSegment seg = new LineSegment(q0, q1); Coordinate segClosestPoint = seg.closestPoint(pt); locs[1] = new GeometryLocation(facetSeq.geom, i, new Coordinate(segClosestPoint)); }