Search in sources :

Example 1 with CartesianTransform

use of ca.nrc.cadc.caom2.types.CartesianTransform in project caom2db by opencadc.

the class PostgreSQLGenerator method generatePolygonApproximation.

ca.nrc.cadc.dali.Polygon generatePolygonApproximation(Circle val, int numVerts) {
    if (numVerts < 4) {
        throw new IllegalArgumentException("number of vertices in approximation too small (min: 4)");
    }
    CartesianTransform trans = CartesianTransform.getTransform(val);
    Point cen = trans.transform(val.getCenter());
    double phi = 2.0 * Math.PI / ((double) numVerts);
    // compute distance to vertices so that the edges are tangent and circle is
    // inside the polygon
    double vdist = val.getRadius() / Math.cos(phi / 2.0);
    // log.info("phi = " + phi + " vdist=" + vdist);
    CartesianTransform inv = trans.getInverseTransform();
    ca.nrc.cadc.dali.Polygon ret = new ca.nrc.cadc.dali.Polygon();
    for (int i = 0; i < numVerts; i++) {
        double x = cen.cval1 + vdist * Math.cos(i * phi);
        double y = cen.cval2 + vdist * Math.sin(i * phi);
        Point p = new Point(x, y);
        p = inv.transform(p);
        ret.getVertices().add(new ca.nrc.cadc.dali.Point(p.cval1, p.cval2));
    }
    return ret;
}
Also used : CartesianTransform(ca.nrc.cadc.caom2.types.CartesianTransform) Point(ca.nrc.cadc.caom2.types.Point) MultiPolygon(ca.nrc.cadc.caom2.types.MultiPolygon) Polygon(ca.nrc.cadc.caom2.types.Polygon) PgSpoint(ca.nrc.cadc.dali.postgresql.PgSpoint) Point(ca.nrc.cadc.caom2.types.Point)

Aggregations

CartesianTransform (ca.nrc.cadc.caom2.types.CartesianTransform)1 MultiPolygon (ca.nrc.cadc.caom2.types.MultiPolygon)1 Point (ca.nrc.cadc.caom2.types.Point)1 Polygon (ca.nrc.cadc.caom2.types.Polygon)1 PgSpoint (ca.nrc.cadc.dali.postgresql.PgSpoint)1