-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPoint.java
62 lines (51 loc) · 1.19 KB
/
Point.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
* Write a description of class Point here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Point
{
// instance variables - replace the example below with your own
public double x;
public double y;
/**
* Constructor for objects of class Point
*/
public Point(double x, double y)
{
this.x = x;
this.y = y;
}
public Point(Point p){
this.x = p.x;
this.y = p.y;
}
public Point scale(double c){
x *= c;
y *= c;
return new Point(x, y);
}
public Point setLength(double length){
if(length == 0 || getLength() == 0){
x = 0;
y = 0;
}
else{
scale(length / getLength());
}
return new Point(x, y);
}
public double getLength(){
return Math.hypot(x, y);
}
public double getTheta(){
return MyMath.angleInRange(Math.toDegrees(Math.atan2(y, x)));
}
public String toString(){
return "x: " + x + " y:" + y;
}
public boolean equals(Point p){
return this.x == p.x && this.y == p.y;
}
}