
org.jeometry.simple.geom3D.primitive.SimpleTriangle Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jeometry-simple Show documentation
Show all versions of jeometry-simple Show documentation
Jeometry, a Mathematic and Geometry library for Java
The newest version!
package org.jeometry.simple.geom3D.primitive;
import java.util.List;
import org.jeometry.Jeometry;
import org.jeometry.factory.JeometryFactory;
import org.jeometry.geom3D.mesh.Edge;
import org.jeometry.geom3D.mesh.Face;
import org.jeometry.geom3D.mesh.Mesh;
import org.jeometry.geom3D.point.Point3D;
import org.jeometry.geom3D.point.Point3DContainer;
import org.jeometry.geom3D.primitive.Polygon3D;
import org.jeometry.geom3D.primitive.Triangle;
/**
* A triangle is a 3D polygon hat relies on 3 non aligned vertices.
* @param the type of underlying 3D points
* @author Julien Seinturier - COMEX S.A. - [email protected] - https://github.com/jorigin/jeometry
* @version {@value Jeometry#version} build {@value Jeometry#BUILD}
* @since 1.0.0
* @see Mesh
* @see Face
* @see Polygon3D
*
*/
public class SimpleTriangle extends SimplePolygon3D implements Triangle{
/**
* The serial version UID.
*/
private static final long serialVersionUID = Jeometry.BUILD;
/**
* The mech.
*/
private Mesh mesh = null;
/**
* The vertices.
*/
private Point3DContainer vertices = null;
/**
* Create a new triangle defined by the given vertices.
* @param vertex1 the first vertex
* @param vertex2 the second vertex
* @param vertex3 the third vertex
*/
public SimpleTriangle(T vertex1, T vertex2, T vertex3) {
vertices = JeometryFactory.createPoint3DContainer(3);
vertices.add(vertex1);
vertices.add(vertex2);
vertices.add(vertex3);
}
@Override
public void setVertices(Point3DContainer vertices) {
if ((vertices != null) && (vertices.size() == 3)) {
this.vertices = vertices;
} else {
throw new IllegalArgumentException("Invalid vertices, must be a list of 3 vertex.");
}
}
@Override
public void inverseVerticesOrder() {
if (vertices != null) {
T i = vertices.get(0);
vertices.set(0, vertices.get(2));
vertices.set(2, i);
}
}
@Override
public Mesh getMesh() {
return mesh;
}
@Override
public void setMesh(Mesh mesh) {
this.mesh = mesh;
}
@Override
public Point3DContainer getVertices() {
return vertices;
}
@Override
public List> getEdges() {
// TODO implements SimpleTriangle.getEdges()
return null;
}
@Override
public T getVertex1() {
if (vertices != null) {
return vertices.get(0);
} else {
return null;
}
}
@Override
public T getVertex2() {
if (vertices != null) {
return vertices.get(1);
} else {
return null;
}
}
@Override
public T getVertex3() {
if (vertices != null) {
return vertices.get(2);
} else {
return null;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy