Class Polyhedron

java.lang.Object
org.episteme.core.mathematics.geometry.polyhedra.Polyhedron
All Implemented Interfaces:
Graph<Point3D>, CollisionShape

public class Polyhedron extends Object implements Graph<Point3D>, CollisionShape
Represents a convex polyhedron in 3D space.

A polyhedron is defined by its vertices and faces. This class supports common operations like computing surface area, volume, and checking convexity.

Since:
1.0
Author:
Silvere Martin-Michiellot, Gemini AI (Google DeepMind)
  • Constructor Details

    • Polyhedron

      public Polyhedron(List<Point3D> vertices, List<int[]> faces)
      Creates a polyhedron from vertices and faces.
      Parameters:
      vertices - list of 3D points
      faces - list of face definitions (each face is an array of vertex indices)
  • Method Details

    • vertexCount

      public int vertexCount()
      Returns the number of vertices.
      Specified by:
      vertexCount in interface Graph<Point3D>
      Returns:
      the number of vertices
    • faceCount

      public int faceCount()
      Returns the number of faces.
    • edgeCount

      public int edgeCount()
      Returns the number of edges (using Euler's formula for convex polyhedra: V - E + F = 2).
    • getVertex

      public Point3D getVertex(int index)
      Returns the vertex at the given index.
    • getFaceVertices

      public List<Point3D> getFaceVertices(int faceIndex)
      Returns the vertices of the face at the given index.
    • centroid

      public Point3D centroid()
      Computes the centroid (center of mass) of the polyhedron.
    • surfaceArea

      public Real surfaceArea()
      Computes the surface area of the polyhedron.
    • volume

      public Real volume()
      Computes the volume of a convex polyhedron using the divergence theorem.
    • isValidEuler

      public boolean isValidEuler()
      Returns true if the polyhedron satisfies Euler's formula (V - E + F = 2).
    • vertices

      public Set<Point3D> vertices()
      Description copied from interface: Graph
      Returns all vertices in this graph.
      Specified by:
      vertices in interface Graph<Point3D>
      Returns:
      unmodifiable set of vertices
    • edges

      public Set<Graph.Edge<Point3D>> edges()
      Description copied from interface: Graph
      Returns all edges in this graph.
      Specified by:
      edges in interface Graph<Point3D>
      Returns:
      unmodifiable set of edges
    • addVertex

      public boolean addVertex(Point3D vertex)
      Description copied from interface: Graph
      Adds a vertex to the graph.
      Specified by:
      addVertex in interface Graph<Point3D>
      Parameters:
      vertex - the vertex to add
      Returns:
      true if vertex was added, false if already present
    • addEdge

      public boolean addEdge(Point3D source, Point3D target)
      Description copied from interface: Graph
      Adds an edge between two vertices.
      Specified by:
      addEdge in interface Graph<Point3D>
      Parameters:
      source - the source vertex
      target - the target vertex
      Returns:
      true if edge was added
    • neighbors

      public Set<Point3D> neighbors(Point3D vertex)
      Description copied from interface: Graph
      Returns neighbors of a vertex.
      Specified by:
      neighbors in interface Graph<Point3D>
      Parameters:
      vertex - the vertex
      Returns:
      set of adjacent vertices
    • degree

      public int degree(Point3D vertex)
      Description copied from interface: Graph
      Returns the degree (number of edges) of a vertex.
      Specified by:
      degree in interface Graph<Point3D>
      Parameters:
      vertex - the vertex
      Returns:
      degree of vertex
    • isDirected

      public boolean isDirected()
      Description copied from interface: Graph
      Checks if this graph is directed.
      Specified by:
      isDirected in interface Graph<Point3D>
      Returns:
      true if directed, false if undirected
    • tetrahedron

      public static Polyhedron tetrahedron()
      Creates a regular tetrahedron with unit edge length.
    • cube

      public static Polyhedron cube()
      Creates a cube with unit edge length centered at origin.
    • octahedron

      public static Polyhedron octahedron()
      Creates a regular octahedron with unit edge length.
    • icosahedron

      public static Polyhedron icosahedron()
      Creates a regular icosahedron.
    • dodecahedron

      public static Polyhedron dodecahedron()
      Creates a regular dodecahedron as the dual of the icosahedron.
    • getSupportPoint

      public Vector<Real> getSupportPoint(Vector<Real> direction)
      Description copied from interface: CollisionShape
      Gets the support point in a given direction (furthest point in that direction). Used for GJK and SAT algorithms.
      Specified by:
      getSupportPoint in interface CollisionShape
      Parameters:
      direction - the direction vector
      Returns:
      the support point in local coordinates
    • getAABB

      public Vector<Real>[] getAABB()
      Description copied from interface: CollisionShape
      compute AABB (Axis Aligned Bounding Box).
      Specified by:
      getAABB in interface CollisionShape
      Returns:
      array of two Vectors {min, max}
    • toString

      public String toString()
      Overrides:
      toString in class Object