Graphics (2D) Rotation: Rotate x Axis

1k views Asked by At

I have a JPanel in which I draw triangles via the method drawPolygon. My Goal is to rotate the graphics around the X axis. I know that there is a method called rotate, but this method rotates only around the Z axis.

How can I rotate a graphic in a JPanel around the X axis?

Example of rotation

If the Graphics 2D library does not have the functionality to do this kind of rotation, please tell me how can I archive my goal otherwise. I don't mind switching to another GUI type like Java-fx or canvas. (But stay in Java)

1

There are 1 answers

3
trashgod On BEST ANSWER

Java 2D provides AffineTransform, but an affine transformation ensures that parallel lines remain parallel after transformation. As an alternative, consider JavaFX 3D, which provides a PerspectiveCamera for perspective projection; this complete example uses Rotate.Y_AXIS, but Rotate.X_AXIS will produce the desired effect. Also consider a Java Advanced Imaging Warp, cited here, which offers a WarpPerspective with PerspectiveTransform.