-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPlane.java
More file actions
144 lines (137 loc) · 3.36 KB
/
Plane.java
File metadata and controls
144 lines (137 loc) · 3.36 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
import java.util.*;
import java.awt.*;
public class Plane extends Polygon
{
public ArrayList<Point3D> points;
public Plane(ArrayList<Point3D> pts)
{
super();
id="Plane";
color=new Color(0,0,255,127);
points=pts;
pan(new Point3D(0,0,0));
}
public Point getScreenPoint(Point3D point, Point p, double d)
{
Vect direc= new Vect(p,new Point(point.x,point.y));
direc.multiply(d/(d+point.z));
if(point.z>=0)
return direc.getPointFrom(p);
return new Point(0,0);
}
public void printPolygon(Graphics page, Point pt, double d)
{
ArrayList<Point> filtered = new ArrayList<Point>();
for(Point3D p : points)
if(p.z>0.01) {
filtered.add(getScreenPoint(p,pt,d));
}
if(filtered.size()==0)
return;
int [] outX = new int[filtered.size()];
int [] outY = new int[filtered.size()];
for(int i=0;i<filtered.size();i++)
{
outX[i]=(int)(filtered.get(i).x);
outY[i]=(int)(filtered.get(i).y);
}
page.setColor(color);
page.fillPolygon(outX,outY,outX.length);
}
public void printPolygon2(Graphics page, Point pt, double d)
{
int count=0;
for(Point3D pnt : points)
if(pnt.z<=0)
count++;
int [] outPointsX = new int[points.size()-count];
int [] outPointsY = new int[points.size()-count];
int cnt=0;
for(int i=0;i<points.size();i++) {
if(points.get(i).z>0) {
Point outP=getScreenPoint(points.get(i),pt,d);
outPointsX[i-cnt]=(int)(outP.x);
outPointsY[i-cnt]=(int)(outP.y);
}
else cnt++;
}
page.setColor(color);
page.fillPolygon(outPointsX,outPointsY,points.size()-count);
}
public void rotate(Point3D p, double ang1, double ang2, double ang3)
{
for(Point3D point : points)
{
Vect xy,xz,yz;
if(Math.abs(ang1)>THRESHOLD)
{
xy = new Vect(new Point(p.x,p.y),new Point(point.x,point.y));
xy=new Vect(xy.getAngle()+ang1,xy.getMag());
point.x=p.x+xy.getX();
point.y=p.y+xy.getY();
}
if(Math.abs(ang2)>THRESHOLD)
{
xz = new Vect(new Point(p.x,p.z),new Point(point.x,point.z));
xz=new Vect(xz.getAngle()+ang2,xz.getMag());
point.x=p.x+xz.getX();
point.z=p.z+xz.getY();
}
if(Math.abs(ang3)>THRESHOLD)
{
yz = new Vect(new Point(p.y,p.z),new Point(point.y,point.z));
yz=new Vect(yz.getAngle()+ang3,yz.getMag());
point.y=p.y+yz.getX();
point.z=p.z+yz.getY();
}
}
}
public void rotateAroundAxis(Point3D p, Vect3D a, double ang)
{
for(Point3D pt : points)
pt.rotateAroundAxis(p,a,ang);
}
public void pan(Point3D d)
{
for(Point3D pt : points)
{
pt.x+=d.x;
pt.y+=d.y;
pt.z+=d.z;
}
}
public ArrayList<Point3D> getPoints()
{
return points;
}
public Point3D getCenter()
{
Point3D out=new Point3D(0,0,0);
for(Point3D pt : points)
{
out.x+=pt.x;
out.y+=pt.y;
out.z+=pt.z;
}
out.x/=points.size();
out.y/=points.size();
out.z/=points.size();
return out;
}
public void explode(double d, Point3D pt)
{
for(Point3D point : points) {
Vect3D direc = new Vect3D(pt,point);
direc.multiply(d);
point=direc.getPointFrom(pt);
}
}
public Vect3D getNormal()
{
Vect3D v1=new Vect3D(points.get(0),points.get(1));
Vect3D v2=new Vect3D(points.get(0),points.get(2));
Vect3D out=v1.crossProduct(v2);
out.normalize();
return out;
}
}