use of com.revolsys.geometry.model.impl.PointDoubleXY in project com.revolsys.open by revolsys.
the class CommonBitsRemover method add.
/**
* Add a geometry to the set of geometries whose common bits are
* being computed. After this method has executed the
* common coordinate reflects the common bits of all added
* geometries.
*
* @param geometry a Geometry to test for common bits
*/
public void add(final Geometry geometry) {
for (final Vertex vertex : geometry.vertices()) {
this.commonBitsX.add(vertex.getX());
this.commonBitsY.add(vertex.getY());
}
this.commonCoord = new PointDoubleXY(this.commonBitsX.getCommon(), this.commonBitsY.getCommon());
}
use of com.revolsys.geometry.model.impl.PointDoubleXY in project com.revolsys.open by revolsys.
the class Points method pointOffset.
public static Point pointOffset(final Point point1, final Point point2, final double xOffset, double yOffset) {
final double distance = point1.distancePoint(point2);
final double projectionFactor = xOffset / distance;
if (Double.isNaN(projectionFactor) || Double.isInfinite(projectionFactor)) {
return new PointDoubleXY(point1.getX() + xOffset, point1.getY() + yOffset);
} else {
final Point point = LineSegmentUtil.pointAlong(point1, point2, projectionFactor);
if (yOffset == 0) {
return new PointDoubleXY(point);
} else {
double angle = point1.angle2d(point2);
if (yOffset > 0) {
angle += MathUtil.PI_OVER_2;
} else {
angle -= MathUtil.PI_OVER_2;
yOffset = -yOffset;
}
final double x = point.getX() + Math.cos(angle) * yOffset;
final double y = point.getY() + Math.sin(angle) * yOffset;
return new PointDoubleXY(x, y);
}
}
}
use of com.revolsys.geometry.model.impl.PointDoubleXY in project com.revolsys.open by revolsys.
the class Triangles method angleBisector.
/**
* Computes the point at which the bisector of the angle ABC cuts the segment
* AC.
*
* @param a
* a vertex of the triangle
* @param b
* a vertex of the triangle
* @param c
* a vertex of the triangle
* @return the angle bisector cut point
*/
static Point angleBisector(final Point a, final Point b, final Point c) {
/**
* Uses the fact that the lengths of the parts of the split segment are
* proportional to the lengths of the adjacent triangle sides
*/
final double len0 = b.distancePoint(a);
final double len2 = b.distancePoint(c);
final double frac = len0 / (len0 + len2);
final double dx = c.getX() - a.getX();
final double dy = c.getY() - a.getY();
final Point splitPt = new PointDoubleXY(a.getX() + frac * dx, a.getY() + frac * dy);
return splitPt;
}
use of com.revolsys.geometry.model.impl.PointDoubleXY in project com.revolsys.open by revolsys.
the class CreateRandomShapeFunctions method randomSegments.
public static Geometry randomSegments(final Geometry g, final int nPts) {
final BoundingBox env = FunctionsUtil.getEnvelopeOrDefault(g);
final GeometryFactory geomFact = FunctionsUtil.getFactoryOrDefault(g);
final double xLen = env.getWidth();
final double yLen = env.getHeight();
final List lines = new ArrayList();
for (int i = 0; i < nPts; i++) {
final double x0 = env.getMinX() + xLen * Math.random();
final double y0 = env.getMinY() + yLen * Math.random();
final double x1 = env.getMinX() + xLen * Math.random();
final double y1 = env.getMinY() + yLen * Math.random();
lines.add(geomFact.lineString(new Point[] { new PointDoubleXY(x0, y0), new PointDoubleXY(x1, y1) }));
}
return geomFact.buildGeometry(lines);
}
use of com.revolsys.geometry.model.impl.PointDoubleXY in project com.revolsys.open by revolsys.
the class CreateRandomShapeFunctions method randomRectilinearWalk.
public static Geometry randomRectilinearWalk(final Geometry g, final int nPts) {
final BoundingBox env = FunctionsUtil.getEnvelopeOrDefault(g);
final GeometryFactory geomFact = FunctionsUtil.getFactoryOrDefault(g);
final double xLen = env.getWidth();
final double yLen = env.getHeight();
final Point[] pts = new Point[nPts];
boolean xory = true;
for (int i = 0; i < nPts; i++) {
Point pt = null;
if (i == 0) {
pt = randomPtInRectangleAround(env.getCentre(), xLen, yLen);
} else {
final double dist = xLen * (Math.random() - 0.5);
double x = pts[i - 1].getX();
double y = pts[i - 1].getY();
if (xory) {
x += dist;
} else {
y += dist;
}
// switch orientation
xory = !xory;
pt = new PointDoubleXY(x, y);
}
pts[i] = pt;
}
return geomFact.lineString(pts);
}
Aggregations