[geotk] Drawing rotated circles. Question on AffineTransform2D.createTransformedShape()

sorel johann johann.sorel at geomatys.fr
Wed Aug 3 04:02:06 EDT 2011


It's the way you calculate your radar circle which is wrong.

I'm sure it's your Elipse2D which is completly flat. you must not have 
<0 values for width and height.
try :
                     Math.abs(bottomRight.x - topLeft.x),
                     Math.abs(bottomRight.y - topLeft.y));

at least you will see your circle.

the reason is when you rotate the map your topleft point is not anymore 
the topleft, same for the bottomRight.


johann

On 03/08/2011 08:46, Thys Meintjes wrote:
> Hi All,
>
> In my Graphic below I'm drawing range rings from a center. To scale 
> the range rings geographically I calculate the circles' bounding boxes 
> and then transform to screen coordinates.
> See below. When I now use the map rotate widget the rings get drawn 
> with the bounding box untransformed. Passing the circle to 
>  AffineTransform2D.createTransformedShape()
> and drawing that shape doesn't draw anything at all... Could anyone 
> spot the bug in my code ?
>
> public class RadarGraphic extends AbstractGraphicJ2D {
>
>     private final static Logger logger = 
> LoggerFactory.getLogger(RadarGraphic.class);
>     private GeodeticCalculator calc;
>     private Radar radar;
>
>     public RadarGraphic(J2DCanvas canvas, Radar radar) {
>         super(canvas, canvas.getObjectiveCRS2D());
>         this.radar = radar;
>         calc = new GeodeticCalculator(DefaultGeographicCRS.WGS84);
>     }
>
>     @Override
>     public void paint(RenderingContext2D context) {
>         final Graphics2D g2d = context.getGraphics();
>         // transform from geographic to screen space
>         final AffineTransform2D transformer = 
> context.getObjectiveToDisplay();
>         
> //transformer.setToRotation(context.getCanvas().getController().getRotation());
>
>         final DirectPosition radarPosition = radar.getAntennaPosition();
>         if (radarPosition == null) {
>             logger.debug("Radar " + radar.getName() + " antenna 
> position not set");
>             return;
>         }
>
>         Point2D.Double center = new 
> Point2D.Double(radarPosition.getOrdinate(0), 
> radarPosition.getOrdinate(1));
>         for (Double range : radar.getRangeList()) {
>             drawRangeRing(g2d, center, range, transformer);
>         }
>
>         drawRadar(g2d, center, transformer);
>     }
>
>     private void drawRangeRing(Graphics2D g2d, Point2D.Double center, 
> Double range, AffineTransform2D transformer) {
>         // topLeft
>         calc.setStartingGeographicPoint(center);
>         calc.setDirection(-45.0, Math.sqrt(2.0) * range);
>         Point2D.Double topLeft = (Point2D.Double) 
> calc.getDestinationGeographicPoint();
>         // bottomRight
>         calc.setStartingGeographicPoint(center);
>         calc.setDirection(135.0, Math.sqrt(2.0) * range);
>         Point2D.Double bottomRight = (Point2D.Double) 
> calc.getDestinationGeographicPoint();
>
>         transformer.transform(topLeft, topLeft);
>         transformer.transform(bottomRight, bottomRight);
>         g2d.setStroke(new BasicStroke(4));
>
>         Shape circle = new Ellipse2D.Double(
>                 topLeft.x,
>                 topLeft.y,
>                 bottomRight.x - topLeft.x,
>                 bottomRight.y - topLeft.y);
>         g2d.setPaint(Color.GREEN);
>         g2d.draw(circle);
>
>
>     }
>
>
> -- 
> Thys Meintjes
>
>
>
> _______________________________________________
> Geotoolkit mailing list
> Geotoolkit at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/geotoolkit

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/geotoolkit/attachments/20110803/6351b888/attachment.html


More information about the Geotoolkit mailing list