-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPyramid.java
More file actions
74 lines (65 loc) · 1.84 KB
/
Pyramid.java
File metadata and controls
74 lines (65 loc) · 1.84 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
import java.util.*;
import java.awt.*;
public class Pyramid extends Polygon
{
public int numSides;
public Pyramid(Point3D p, int n, double r, double h)
{
super();
id="Pyramid";
numSides=n;
ArrayList<Point3D> points1 = new ArrayList<Point3D>();
ArrayList<Point3D> points2 = new ArrayList<Point3D>();
Vect direc = new Vect(Math.PI/4,r);
for(int i=0;i<n;i++)
{
Point pt=direc.getPointFrom(new Point(p.x,p.y));
points1.add(new Point3D(pt.x,pt.y,p.z));
direc=new Vect(direc.getAngle()+Math.PI*2/n,r);
}
for(Point3D pt : points1)
lines.add(new Line3D(new Point3D(p.x,p.y,p.z+h),pt));
for(int i=1;i<points1.size();i++)
lines.add(new Line3D(points1.get(i-1),points1.get(i)));
lines.add(new Line3D(points1.get(0),points1.get(points1.size()-1)));
pan(new Point3D(0,0,0));
}
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);
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);
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);
return out;
}
}