-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPolygon.java
More file actions
41 lines (31 loc) · 1.15 KB
/
Polygon.java
File metadata and controls
41 lines (31 loc) · 1.15 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
package labs.introtoprogramming.lab5.object.Parser;
import labs.introtoprogramming.lab5.geometry.Vector3;
import java.util.ArrayList;
import java.util.List;
public class Polygon {
private List<Vertex> vertices = new ArrayList<>();
private Vector3 polygonNormal;
public List<Vertex> getVertices() {
return vertices;
}
public void setVertecies(ArrayList<Vertex> vertices) {
this.vertices = vertices;
}
public void addVertex(Vertex vertex) {vertices.add(vertex);}
public void setVertices(ArrayList<Vertex> vertices) {
this.vertices = vertices;
}
public Vector3 getPolygonNormal() {
return polygonNormal;
}
public void calculatePolygonNormalTriangle() {
if (vertices.size() == 3) {
Vector3 fromOneToTwo = vertices.get(0).getVertexG().subtract(vertices.get(1).getVertexG());
Vector3 fromOneToThree = vertices.get(0).getVertexG().subtract(vertices.get(2).getVertexG());
polygonNormal = fromOneToTwo.crossProduct(fromOneToThree);
}
}
public void setPolygonNormal(Vector3 polygonNormal) {
this.polygonNormal = polygonNormal;
}
}