EOS 2  1.1.0
Einfache Objektbasierte Sprache
Matrix.java
gehe zur Dokumentation dieser Datei
1 package de.lathanda.eos.base.math;
2 
3 import java.awt.geom.AffineTransform;
4 
20 public class Matrix {
21 
25  private double x11;
29  private double x12;
33  private double x21;
37  private double x22;
41  private double tx;
45  private double ty;
46 
51  public Matrix() {
52  x11 = 1.0;
53  x12 = 0.0;
54  x21 = 0.0;
55  x22 = 1.0;
56  tx = 0.0;
57  ty = 0.0;
58  }
59 
67  public Matrix(double rotationAngle) {
68  x11 = Math.cos(rotationAngle);
69  x12 = -Math.sin(rotationAngle);
70  x21 = Math.sin(rotationAngle);
71  x22 = Math.cos(rotationAngle);
72  tx = 0.0;
73  ty = 0.0;
74  }
75 
82  public Matrix(Vector translation) {
83  x11 = 1.0;
84  x12 = 0.0;
85  x21 = 0.0;
86  x22 = 1.0;
87  tx = translation.getdx();
88  ty = translation.getdy();
89  }
90 
98  public Matrix(double sx, double sy) {
99  x11 = sx;
100  x12 = 0.0;
101  x21 = 0.0;
102  x22 = sy;
103  tx = 0.0;
104  ty = 0.0;
105  }
106 
117  public Matrix(double xt, double yt, double a, double sx, double sy) {
118  double c = Math.cos(a);
119  double s = Math.sin(a);
120  x11 = sx * c;
121  x12 = -sy * s;
122  x21 = sx * s;
123  x22 = sy * c;
124  tx = xt;
125  ty = yt;
126  }
127 
133  public AffineTransform convert() {
134  return new AffineTransform(x11, x21, x12, x22, tx, ty);
135  }
136 
143  public Vector transform(Vector v) {
144  double xa = v.getdx();
145  double ya = v.getdy();
146  double xb = xa * x11 + ya * x12 + tx;
147  double yb = xa * x21 + ya * x22 + ty;
148  return new Vector(xb, yb);
149  }
150 
157  public Point transform(Point p) {
158  double xa = p.getX();
159  double ya = p.getY();
160  double xb = xa * x11 + ya * x12 + tx;
161  double yb = xa * x21 + ya * x22 + ty;
162  return new Point(xb, yb);
163  }
164 
173  public void transform(double[] x, double[] y, double[] xt, double[] yt) {
174  for (int i = 0; i < x.length; i++) {
175  xt[i] = x[i] * x11 + y[i] * x12 + tx;
176  yt[i] = x[i] * x21 + y[i] * x22 + ty;
177  }
178  }
179 
186  public Matrix transform(Matrix N) {
187  Matrix u = new Matrix();
188  u.x11 = x11 * N.x11 + x12 * N.x21;
189  u.x12 = x11 * N.x12 + x12 * N.x22;
190  u.x21 = x21 * N.x21 + x12 * N.x21;
191  u.x22 = x21 * N.x12 + x22 * N.x22;
192  u.tx = x11 * N.tx + x12 * N.ty + tx;
193  u.ty = x21 * N.tx + x22 * N.ty + ty;
194  return u;
195  }
196 
202  public double[] asArray() {
203  return new double[]{x11, x12, tx, x21, x22, ty, 0d, 0d, 1d};
204  }
205 }
Matrix(double sx, double sy)
Definition: Matrix.java:98
Matrix(double rotationAngle)
Definition: Matrix.java:67
Matrix(double xt, double yt, double a, double sx, double sy)
Definition: Matrix.java:117
Vector transform(Vector v)
Definition: Matrix.java:143
Matrix(Vector translation)
Definition: Matrix.java:82
Matrix transform(Matrix N)
Definition: Matrix.java:186
void transform(double[] x, double[] y, double[] xt, double[] yt)
Definition: Matrix.java:173
AffineTransform convert()
Definition: Matrix.java:133
Impressum