-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPointMath.java
More file actions
32 lines (27 loc) · 834 Bytes
/
PointMath.java
File metadata and controls
32 lines (27 loc) · 834 Bytes
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
public class PointMath
{
// get the distance between two points
public static double distance(double x1, double y1, double x2, double y2)
{
double a = x2 - x1;
double b = y2 - y1;
return Math.sqrt(a * a + b * b);
}
// get the magnitude of a vector
public static double magnitude(double x, double y)
{
return distance(0, 0, x, y);
}
// https://academo.org/demos/rotation-about-point/
// rotate a point around an origin by a rotation
public static Point transformPoint(double originX, double originY, double pointX, double pointY, double degrees)
{
double radians = Math.toRadians(degrees);
double x = pointX - originX;
double y = pointY - originY;
return new Point(
x * Math.cos(radians) - y * Math.sin(radians) + originX,
y * Math.cos(radians) + x * Math.sin(radians) + originY
);
}
}