-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathVect3D.java
More file actions
146 lines (131 loc) · 2.44 KB
/
Vect3D.java
File metadata and controls
146 lines (131 loc) · 2.44 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
public class Vect3D
{
public double x;
public double y;
public double z;
public double mag;
public Vect3D()
{
x=0;
y=0;
z=0;
mag=0;
}
public Vect3D(double xi,double yi,double zi)
{
x=xi;
y=yi;
z=zi;
}
public Vect3D(Vect3D o)
{
x=o.x;
y=o.y;
z=o.z;
// mag=Math.sqrt(x*x+y*y+z*z);
}
public Vect3D(Point3D p1, Point3D p2)
{
x=p2.x-p1.x;
y=p2.y-p1.y;
z=p2.z-p1.z;
// mag=Math.sqrt(x*x+y*y+z*z);
}
public Vect3D(Point3D p1)
{
x=p1.x;
y=p1.y;
z=p1.z;
}
public Vect3D(double ang1, double ang2, double ang3, double m)
{
mag=m;
Point3D point = new Point3D(m,0,0);
point.rotate(new Point3D(0,0,0),ang1,ang2,ang3);
x=point.x;
y=point.y;
z=point.z;
}
public double getMag()
{
return Math.sqrt(x*x+y*y+z*z);
}
public double getMagSquared()
{
return x*x+y*y;
}
public void normalize()
{
mag=getMag();
x/=mag;
y/=mag;
z/=mag;
}
public Vect3D getNormalized()
{
mag=getMag();
return new Vect3D(x/mag,y/mag,z/mag);
}
public void rotateVect(Point3D cent, double ang1, double ang2, double ang3)
{
PointP pt = new PointP(new Point3D(x,y,z));
pt.rotate(cent,ang1,ang2,ang3);
Point3D point = pt.point;
x=point.x;
y=point.y;
z=point.z;
}
public Point3D getPointFrom(Point3D p)
{
return new Point3D(p.x+x,p.y+y,p.z+z);
}
public Point3D getNegPointFrom(Point3D p)
{
return new Point3D(p.x-x,p.y-y,p.z-z);
}
public void multiply(double d)
{
x*=d;
y*=d;
z*=d;
}
public Vect3D times(double d)
{
return new Vect3D(x*d,y*d,z*d);
}
public Vect3D addVect(Vect3D v)
{
return new Vect3D(new Point3D(0,0,0),new Point3D(x+v.x,y+v.y,z+v.z));
}
public Vect3D subtractVect(Vect3D v)
{
return new Vect3D(new Point3D(0,0,0),new Point3D(x-v.x,y-v.y,z-v.z));
}
public void setMag(double m)
{
double mG=getMag();
x=x*m/mG;
y=y*m/mG;
z=z*m/mG;
}
public double dotProduct(Vect3D b)
{
return x*b.x+y*b.y+z*b.z;
}
public Vect3D crossProduct(Vect3D b)
{
return new Vect3D(new Point3D(0,0,0),new Point3D(y*b.z-z*b.y,z*b.x-x*b.z,x*b.y-y*b.x));
}
public Vect3D getXZPerp1()
{
return new Vect3D(new Point3D(0,0,0),new Point3D(-z,y,x));
}
public Vect3D getXZPerp2()
{
return new Vect3D(new Point3D(0,0,0),new Point3D(z,y,-x));
}
public String toString()
{
return "["+x+","+y+","+z+"]";
}
}