1 package demo;
2
3 import org.djutils.draw.Transform2d;
4 import org.djutils.draw.Transform3d;
5 import org.djutils.draw.line.PolyLine2d;
6 import org.djutils.draw.point.Point2d;
7 import org.djutils.draw.point.Point3d;
8
9
10
11
12
13
14
15
16
17
18 public final class TransformDemos
19 {
20
21
22
23 private TransformDemos()
24 {
25
26 }
27
28
29
30
31
32 public static void main(final String... args)
33 {
34 translateAndRotate();
35 shear2d();
36 shear3d();
37 scale();
38 transformPolyLine();
39 }
40
41
42
43
44 public static void translateAndRotate()
45 {
46 System.out.println("Translate and rotate");
47 Point3d point = new Point3d(1, 0, 0);
48 System.out.println(point);
49 Transform3d transform1 = new Transform3d();
50 transform1.translate(2, 5, 8);
51 System.out.println(transform1.transform(point));
52 transform1.rotY(Math.PI / 2);
53 System.out.println(transform1.transform(point));
54
55 Transform3d transform2 = new Transform3d().translate(2, 5, 8).rotY(Math.PI / 2);
56 System.out.println(transform2.transform(point));
57 }
58
59
60
61
62 public static void shear2d()
63 {
64 System.out.println("2D shear");
65 Transform2d transform = new Transform2d().shear(2, 3);
66 for (int x = 0; x < 2; x++)
67 {
68 for (int y = 0; y < 2; y++)
69 {
70 Point2d p = new Point2d(x, y);
71 System.out.println(p + " -> " + transform.transform(p));
72 }
73 }
74 }
75
76
77
78
79 public static void shear3d()
80 {
81 System.out.println("3D shear");
82 Transform3d transform = new Transform3d().shearXY(2, 3);
83 for (int x = 0; x < 2; x++)
84 {
85 for (int y = 0; y < 2; y++)
86 {
87 for (int z = 0; z < 2; z++)
88 {
89 Point3d p = new Point3d(x, y, z);
90 System.out.println(p + " -> " + transform.transform(p));
91 }
92 }
93 }
94 }
95
96
97
98
99 public static void scale()
100 {
101 System.out.println("Scaling");
102 Transform2d transform = new Transform2d().scale(4, 6);
103 for (int x = 0; x < 2; x++)
104 {
105 for (int y = 0; y < 2; y++)
106 {
107 Point2d p = new Point2d(x, y);
108 System.out.println(p + " -> " + transform.transform(p));
109 }
110 }
111 }
112
113
114
115
116 public static void transformPolyLine()
117 {
118 System.out.println("Transforming a multi-point Drawable");
119 PolyLine2d line = new PolyLine2d(new Point2d(1, 2), new Point2d(2, 3), new Point2d(5, 0));
120 System.out.println(line);
121 Transform2d transform = new Transform2d().scale(2, 3);
122 PolyLine2d transformedLine = new PolyLine2d(transform.transform(line.getPoints()));
123 System.out.println(transformedLine);
124 }
125 }