Coordinate Space Transformations

If you wanted to rotate or otherwise transform a graphics object and then redraw it, there would be two obvious ways to go. One way, which is generally impractical, is to transform each point of the graphics object and then render the transformed object. Any reasonably complicated shape would require many hundreds of transforms. The preferred way is to transform the user space, draw on it, and then render the user space to the output device.

 class myCustomCanvas extends Canvas { public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; g2d.setColor(Color.red); //setting context Rectangle2D sq1 = new Rectangle2D.Float(0.f,0.f,175.0f,175.0f); //translate user space to center g2d.translate(this.getSize().width/2, ...

Get Java™ Media APIs: Cross-Platform Imaging, Media, and Visualization now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.