Java AffineTransform setToQuadrantRotation(int numquadrants, double anchorx, double anchory)

PreviousNext

Java AffineTransform setToQuadrantRotation(int numquadrants, double anchorx, double anchory) Sets this transform to a translated rotation transformation that rotates coordinates by the specified number of quadrants around the specified anchor point.

Introduction

Sets this transform to a translated rotation transformation that rotates coordinates by the specified number of quadrants around the specified anchor point.

This operation is equivalent to calling: setToRotation(numquadrants * Math.PI / 2.0, anchorx, anchory); Rotating by a positive number of quadrants rotates points on the positive X axis toward the positive Y axis.

Syntax

The method setToQuadrantRotation() from AffineTransform is declared as:

public void setToQuadrantRotation(int numquadrants, double anchorx, double anchory)

Parameter

The method setToQuadrantRotation() has the following parameter:

  • int numquadrants - the number of 90 degree arcs to rotate by
  • double anchorx - the X coordinate of the rotation anchor point
  • double anchory - the Y coordinate of the rotation anchor point

Example

The following code shows how to use Java AffineTransform setToQuadrantRotation(int numquadrants, double anchorx, double anchory)

Example 1

import java.awt.Container;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;

import javax.swing.JComponent;
import javax.swing.JFrame;

public class Main {
    public static void main(String[] args) {
        JFrame jf = new JFrame("Demo");
        Container cp = jf.getContentPane();
        MyCanvas tl = new MyCanvas();
        cp.add(tl);//    ww  w    . d   e m o   2 s   .  c   o  m
        jf.setSize(300, 200);
        jf.setVisible(true);
    }
}

class MyCanvas extends JComponent {

    public void paint(Graphics g) {
        Shape shape = new Rectangle2D.Float(100, 50, 80, 80);

        Graphics2D g2 = (Graphics2D) g;

        AffineTransform at = new AffineTransform();
        at.setToQuadrantRotation(2, 0.5, 0.5);

        g2.setTransform(at);
        g2.draw(shape);

    }
}

Example 2

import java.awt.Container;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;

import javax.swing.JComponent;
import javax.swing.JFrame;

public class Main {
    public static void main(String[] args) {
        JFrame jf = new JFrame("Demo");
        Container cp = jf.getContentPane();
        MyCanvas tl = new MyCanvas();
        cp.add(tl);//   w w    w.    de  m   o   2 s  .  c o   m 
        jf.setSize(300, 200);
        jf.setVisible(true);
    }
}

class MyCanvas extends JComponent {

    public void paint(Graphics g) {
        Shape shape = new Rectangle2D.Float(100, 50, 80, 80);

        Graphics2D g2 = (Graphics2D) g;

        AffineTransform at = new AffineTransform();
        at.setToQuadrantRotation(2, 0.5, 0.5);

        System.out.println(at.getScaleX());

        g2.setTransform(at);
        g2.draw(shape);

    }
}

Example 3

import java.awt.Container;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;

import javax.swing.JComponent;
import javax.swing.JFrame;

public class Main {
    public static void main(String[] args) {
        JFrame jf = new JFrame("Demo");
        Container cp = jf.getContentPane();
        MyCanvas tl = new MyCanvas();
        cp.add(tl);/*  w w   w  . d e   m   o 2  s  . c    o m */
        jf.setSize(300, 200);
        jf.setVisible(true);
    }
}

class MyCanvas extends JComponent {

    public void paint(Graphics g) {
        Shape shape = new Rectangle2D.Float(100, 50, 80, 80);

        Graphics2D g2 = (Graphics2D) g;

        AffineTransform at = new AffineTransform();
        at.setToQuadrantRotation(2, 0.5, 0.5);

        System.out.println(at.getScaleY());

        g2.setTransform(at);
        g2.draw(shape);

    }
}
PreviousNext

Related