Hi

I have a method below that is passed a circle in world coor. and then proceeds to translate and scale the circle so that it is in the centre of a panel and fills the panel. My class ScreenWorldCoordinateSystem2D calculates world-screen mapping.

So, to draw a circle in screen coor space I translate the top left corner of the circle and scale it using AffineTransform. My own method Matrix3x3.fromJavaAffineTransform() is debug code to a human-readable copy of the running 3x3 transform matrix - all of which appear correct.

Rather than being centred in the middle of a panel it is clipped towards the bottom of the panel.

I'm totally baffled by this as all the transformation code seems ok.

Thanks for any help.

Graham

Java Code:
    private void paintCircle(final Circle2D circle, final Graphics2D g2)
    {
        // world object
        Point2D  centre   = circle.getCentre();
        double   radius   = circle.getRadius();
        double   diameter = 2.0 * radius;

        // screen coor
        RenderManager2D rman = RenderManager2D.getRenderManager2D();
        ScreenWorldCoordinateSystem2D coorSys = rman.getScreenWorldCoordinateSystem();
        coorSys.setWorldPointXY(centre.getX(),centre.getY());
        coorSys.mapWorldPointToScreenPoint();
        int centreScreenX  = (int)coorSys.getScreenPointX();
        int centreScreenY  = (int)coorSys.getScreenPointY();
        int topLeftScreenX = centreScreenX - (int)radius;
        int topLeftScreenY = centreScreenY - (int)radius;

        double scaleX = coorSys.scaleX();
        double scaleY = coorSys.scaleY();
        double minScale = scaleX;
        if (scaleY < minScale)
            minScale = scaleY;

        // circle
        java.awt.geom.Ellipse2D.Double jcircle = new java.awt.geom.Ellipse2D.Double(0, 0, diameter, diameter);

        // scale
        AffineTransform tx = new AffineTransform();
        tx.translate(topLeftScreenX,topLeftScreenY);

        double[] flatmatrix = new double[6];
        tx.getMatrix(flatmatrix);
        Matrix3x3 m3x3 = Matrix3x3.fromJavaAffineTransform(flatmatrix);

        tx.scale(minScale, minScale);

        tx.getMatrix(flatmatrix);
        m3x3 = Matrix3x3.fromJavaAffineTransform(flatmatrix);

        g2.setTransform(tx);
        
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        g2.setColor(Color.BLACK);
        g2.draw(jcircle);
        g2.fill(jcircle);
    }