EOS 2  1.1.0
Einfache Objektbasierte Sprache
Triangle.java
gehe zur Dokumentation dieser Datei
1 package de.lathanda.eos.geo;
2 
3 import de.lathanda.eos.base.layout.BalancePoint;
4 
5 import de.lathanda.eos.base.Picture;
6 import de.lathanda.eos.base.layout.BoundingBox;
7 import de.lathanda.eos.base.math.Point;
8 import de.lathanda.eos.base.layout.Transform;
9 
15 public class Triangle extends FilledFigure {
16  private static final int A = 0;
17  private static final int B = 1;
18  private static final int C = 2;
19  Point[] points;
20 
21  public Triangle() {
22  points = new Point[3];
23  points[A] = new Point(-10,0);
24  points[B] = new Point(10,0);
25  points[C] = new Point(0,10);
26  recenter();
27  }
28  @Override
29  protected void drawObject(Picture p) {
30  p.drawPolygon(points);
31  }
32  @Override
33  protected void scaleInternal(double factor) {
34  points[A].scale(factor);
35  points[B].scale(factor);
36  points[C].scale(factor);
37  }
38  public void setCorners(double x1, double y1, double x2, double y2, double x3, double y3) {
40  points[A] = new Point(x1, y1);
41  points[B] = new Point(x2, y2);
42  points[C] = new Point(x3, y3);
43  recenter();
45  }
46 
47  public void mirrorX() {
48  points[A].negateX();
49  points[B].negateX();
50  points[C].negateX();
51  fireDataChanged();
52  }
53 
54  public void mirrorY() {
55  points[A].negateY();
56  points[B].negateY();
57  points[C].negateY();
58  fireDataChanged();
59  }
60 
61  @Override
62  public Figure copy() {
63  Triangle tri = (Triangle)super.copy();
64  tri.points = new Point[3];
65  for(int i = 0; i < 3; i++) {
66  tri.points[i] = new Point(points[i]);
67  }
68  return tri;
69  }
70 
71  @Override
73  double area;
74  double xa = points[A].getX();
75  double xb = points[B].getX();
76  double xc = points[C].getX();
77  double ya = points[A].getY();
78  double yb = points[B].getY();
79  double yc = points[C].getY();
80  area = Math.abs((xa-xb)*(ya-yc)-(ya-yb)*(xa-xc));
81  return new BalancePoint(area, getX(), getY());
82  }
83  private void recenter() {
84  double x = 0;
85  double y = 0;
86  for(Point p : points) {
87  x += p.getX();
88  y += p.getY();
89  }
90  x /= 3d;
91  y /= 3d;
92  this.moveInternal(x + getX(), y + getY());
93  points[A].move(-x, -y);
94  points[B].move(-x, -y);
95  points[C].move(-x, -y);
96  }
97  @Override
99  Transform t = base.transform(own);
100  BoundingBox bound = new BoundingBox();
101  bound.add(t.transform(points[A]));
102  bound.add(t.transform(points[B]));
103  bound.add(t.transform(points[C]));
104  return bound;
105  }
106  public String getAText() {
107  return getTransformedPosition(points[A]).toString();
108  }
109  public String getBText() {
110  return getTransformedPosition(points[B]).toString();
111  }
112  public String getCText() {
113  return getTransformedPosition(points[C]).toString();
114  }
115 }
abstract void drawPolygon(double[] x, double[] y)
Geometrische Transformation.
Definition: Transform.java:13
Transform transform(Transform child)
Definition: Transform.java:83
void scale(double factor)
Definition: Point.java:57
void moveInternal(double x, double y)
Definition: Figure.java:118
Point getTransformedPosition(Point point)
Definition: Figure.java:220
void drawObject(Picture p)
Definition: Triangle.java:29
BalancePoint getBalancePoint()
Definition: Triangle.java:72
BoundingBox calculateBoundingBox(Transform base, Transform own)
Definition: Triangle.java:98
void scaleInternal(double factor)
Definition: Triangle.java:33
void setCorners(double x1, double y1, double x2, double y2, double x3, double y3)
Definition: Triangle.java:38
Impressum