-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathArrow3D.java
More file actions
123 lines (112 loc) · 3.09 KB
/
Arrow3D.java
File metadata and controls
123 lines (112 loc) · 3.09 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
import java.util.*;
import java.awt.*;
public class Arrow3D extends Polygon
{
public int numSides;
public int numLinesPrism;
public Arrow3D(Point3D p, int r, int h, double ang1, double ang2, double ang3, int n)
{
this(p,r,h,n);
rotate(p,ang1,ang2,ang3);
}
public Arrow3D(Point3D p, double r, double h, int n)
{
super();
id="Arrow3D";
numSides=n;
Prism prism = new Prism(p,n,r,h);
Pyramid pyramid = new Pyramid(new Point3D(p.x,p.y,p.z+h),n,r*3,r*5);
for(Line3D line : prism.lines)
lines.add(line);
numLinesPrism=lines.size();
for(Line3D line : pyramid.lines)
lines.add(line);
pan(new Point3D(0,0,0));
rotate(p,0,-Math.PI/2,0);
}
public Arrow3D(Point3D p, double r, double h, Vect3D v, int n)
{
this(p,r,h,n);
Vect3D direc = new Vect3D(new Point3D(1,0,0));
Vect3D axis = v.crossProduct(direc);
double foo=direc.dotProduct(v);
double ang = Math.acos(foo/(v.getMag()));
if(foo>0)
ang=-ang;
//System.out.println(axis+"\t"+ang);
rotateAroundAxis(p,axis,ang);
}
public void drawFilled(Graphics page, Point pt, double d)
{
ArrayList<Plane> planes = getPlanes();
for(Plane plane : planes)
plane.printPolygon(page,pt,d);
}
public ArrayList<Plane> getPlanes()
{
Plane plane;
ArrayList<Plane> out= new ArrayList<Plane>();
ArrayList<Point3D> add;
for(int i=0;i<numSides-1;i++)
{
add = new ArrayList<Point3D>();
add.add(lines.get(i).point1);
add.add(lines.get(i).point2);
add.add(lines.get(i+1).point2);
add.add(lines.get(i+1).point1);
plane= new Plane(add);
plane.color=color;
out.add(plane);
}
add= new ArrayList<Point3D>();
add.add(lines.get(0).point1);
add.add(lines.get(0).point2);
add.add(lines.get(numSides-1).point2);
add.add(lines.get(numSides-1).point1);
plane= new Plane(add);
plane.color=color;
out.add(plane);
add= new ArrayList<Point3D>();
for(int i=0;i<numSides;i++)
{
add.add(lines.get(i).point1);
}
plane= new Plane(add);
plane.color=color;
out.add(plane);
add= new ArrayList<Point3D>();
for(int i=0;i<numSides;i++)
{
add.add(lines.get(i).point2);
}
plane= new Plane(add);
plane.color=color;
out.add(plane);
for(int i=numLinesPrism;i<numSides-1+numLinesPrism;i++)
{
add = new ArrayList<Point3D>();
add.add(lines.get(i).point1);
add.add(lines.get(i).point2);
add.add(lines.get(i+1).point2);
plane= new Plane(add);
plane.color=color;
out.add(plane);
}
add= new ArrayList<Point3D>();
add.add(lines.get(numLinesPrism).point1);
add.add(lines.get(numLinesPrism).point2);
add.add(lines.get(numSides-1+numLinesPrism).point2);
plane= new Plane(add);
plane.color=color;
out.add(plane);
add= new ArrayList<Point3D>();
for(int i=numLinesPrism;i<numSides+numLinesPrism;i++)
{
add.add(lines.get(i).point2);
}
plane= new Plane(add);
plane.color=color;
out.add(plane);
return out;
}
}