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;
}
Aggregations