Harrison Tarr
2016-02-26 18:22:07 UTC
Hi,
Iâm trying to use JTS to create a Polygon representation of an ellipse. Iâm able to create the polygon with the correct dimensions and location, but when I try to rotate it, it behaves weirdly. Iâve attached a video of what the rotation looks like through 0, PI/6, PI/4, PI/3, PI/2, and PI. I would expect it to rotate around the center point like a hand on a clock, but instead it seems to stretch and be stuck between approx 0 and 30 degrees.
The following is my code, where rotation is in radians:
shapeFactory.setCentre(coordinate);
shapeFactory.setWidth(minorRadiusAngle * 2);
shapeFactory.setHeight(majorRadiusAngle * 2);
shapeFactory.setRotation(rotation);
shapeFactory.setNumPoints(precision);
/*
Get the polygon representation of the ellipse
*/
Polygon ellipseAsPoly = shapeFactory.createEllipse();
/*
* Use a WKT writer to return a WKT representation of the polygon representation of the ellipse
*/
WKTWriter writer = new WKTWriter();
return writer.write(ellipseAsPoly);
I have also tried replacing the setCentre, setWidth, setHeight calls with:
Envelope envelope = new Envelope(new Coordinate(coordinate.x - minorRadiusAngle,
coordinate.y - majorRadiusAngle),
new Coordinate(coordinate.x + minorRadiusAngle, coordinate.y + majorRadiusAngle));
shapeFactory.setEnvelope(envelope);
The switch between envelope or setting height, width, and center has no effect on the resulting WKT. Any help with this would be greatly appreciated and Iâm happy to supply more information if you need.
Thanks,
Harrison
Iâm trying to use JTS to create a Polygon representation of an ellipse. Iâm able to create the polygon with the correct dimensions and location, but when I try to rotate it, it behaves weirdly. Iâve attached a video of what the rotation looks like through 0, PI/6, PI/4, PI/3, PI/2, and PI. I would expect it to rotate around the center point like a hand on a clock, but instead it seems to stretch and be stuck between approx 0 and 30 degrees.
The following is my code, where rotation is in radians:
shapeFactory.setCentre(coordinate);
shapeFactory.setWidth(minorRadiusAngle * 2);
shapeFactory.setHeight(majorRadiusAngle * 2);
shapeFactory.setRotation(rotation);
shapeFactory.setNumPoints(precision);
/*
Get the polygon representation of the ellipse
*/
Polygon ellipseAsPoly = shapeFactory.createEllipse();
/*
* Use a WKT writer to return a WKT representation of the polygon representation of the ellipse
*/
WKTWriter writer = new WKTWriter();
return writer.write(ellipseAsPoly);
I have also tried replacing the setCentre, setWidth, setHeight calls with:
Envelope envelope = new Envelope(new Coordinate(coordinate.x - minorRadiusAngle,
coordinate.y - majorRadiusAngle),
new Coordinate(coordinate.x + minorRadiusAngle, coordinate.y + majorRadiusAngle));
shapeFactory.setEnvelope(envelope);
The switch between envelope or setting height, width, and center has no effect on the resulting WKT. Any help with this would be greatly appreciated and Iâm happy to supply more information if you need.
Thanks,
Harrison