EOS 2  1.1.0
Einfache Objektbasierte Sprache
Point.java
gehe zur Dokumentation dieser Datei
1 package de.lathanda.eos.base.math;
2 
3 import java.text.MessageFormat;
4 
12 public class Point {
13 
17  protected double x;
21  protected double y;
22 
29  public Point(double x, double y) {
30  this.x = x;
31  this.y = y;
32  }
33 
39  public Point(Vector v) {
40  this.x = v.getdx();
41  this.y = v.getdy();
42  }
43 
49  public Point(Point p) {
50  this.x = p.getX();
51  this.y = p.getY();
52  }
57  public void scale(double factor) {
58  x *= factor;
59  y *= factor;
60  }
66  public double getX() {
67  return x;
68  }
69 
75  public double getY() {
76  return y;
77  }
78  public void setX(double x) {
79  this.x = x;
80  }
81  public void setY(double y) {
82  this.y = y;
83  }
91  public double getDistance(Point b) {
92  return getDistance(b.getX(), b.getY());
93  }
94 
103  public double getDistance(double x, double y) {
104  return Math.sqrt((x - this.x) * (x - this.x) + (y - this.y) * (y - this.y));
105  }
106  public void negateX() {
107  x = -x;
108  }
109  public void negateY() {
110  y = -y;
111  }
112 
113  public double getPhi() {
114  double phi = Math.atan(y/x);
115  if (x < 0) {
116  return phi + Math.PI;
117  } else {
118  return phi;
119  }
120  }
121  public double getR() {
122  return Math.sqrt(x*x+y*y);
123  }
130  public void move(double dX, double dY) {
131  x += dX;
132  y += dY;
133  }
134 
140  public void move(Vector v) {
141  x += v.getdx();
142  y += v.getdy();
143  }
144 
151  public void moveTo(double x, double y) {
152  this.x = x;
153  this.y = y;
154  }
155 
161  public void moveTo(Point p) {
162  this.x = p.getX();
163  this.y = p.getY();
164  }
165 
171  @Override
172  public String toString() {
173  return MessageFormat.format("({0,number,#.00}|{1,number,#.00})",
174  new Object[]{x, y});
175  }
176 }
double getDistance(double x, double y)
Definition: Point.java:103
void moveTo(double x, double y)
Definition: Point.java:151
double getDistance(Point b)
Definition: Point.java:91
double y
y Koordinate
Definition: Point.java:21
void scale(double factor)
Definition: Point.java:57
double x
x Koordinate
Definition: Point.java:17
Point(double x, double y)
Definition: Point.java:29
void move(double dX, double dY)
Definition: Point.java:130
Impressum