Class Sphere

java.lang.Object
raymarcher.meshes.Sphere
All Implemented Interfaces:
Mesh

public class Sphere
extends java.lang.Object
implements Mesh
An implementation of the Mesh interface that renders a sphere
  • Field Summary

    Fields
    Modifier and Type Field Description
    private java.awt.Color meshColor
    The color of the mesh
    private Vector3 position
    The position of the sphere's center
    private double radius
    The radius of the sphere
  • Constructor Summary

    Constructors
    Constructor Description
    Sphere​(Vector3 position, double radius, java.awt.Color meshColor)
    Create a sphere mesh
  • Method Summary

    Modifier and Type Method Description
    java.awt.Color getMeshColor()
    Gives the mesh's color
    Vector3 getPosition()  
    double getRadius()  
    double sdf​(Vector3 position)
    The signed distance function for the mesh, which tells the mesh's distance to a point in 3D space
    void setMeshColor​(java.awt.Color meshColor)  
    void setPosition​(Vector3 position)  
    void setRadius​(double radius)  

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • position

      private Vector3 position
      The position of the sphere's center
    • radius

      private double radius
      The radius of the sphere
    • meshColor

      private java.awt.Color meshColor
      The color of the mesh
  • Constructor Details

    • Sphere

      public Sphere​(Vector3 position, double radius, java.awt.Color meshColor)
      Create a sphere mesh
      Parameters:
      position - The position in 3D space to center the sphere
      radius - The radius of the sphere
      meshColor - The color of the sphere
  • Method Details

    • getPosition

      public Vector3 getPosition()
      Returns:
      the current position of the center of the sphere
    • setPosition

      public void setPosition​(Vector3 position)
      Parameters:
      position - the new center of the sphere
    • getRadius

      public double getRadius()
      Returns:
      the sphere's current radius
    • setRadius

      public void setRadius​(double radius)
      Parameters:
      radius - the new radius of the sphere
    • setMeshColor

      public void setMeshColor​(java.awt.Color meshColor)
      Parameters:
      meshColor - The new color to set the mesh to
    • getMeshColor

      public java.awt.Color getMeshColor()
      Description copied from interface: Mesh
      Gives the mesh's color
      Specified by:
      getMeshColor in interface Mesh
      Returns:
      The color of the mesh
    • sdf

      public double sdf​(Vector3 position)
      Description copied from interface: Mesh
      The signed distance function for the mesh, which tells the mesh's distance to a point in 3D space
      Specified by:
      sdf in interface Mesh
      Parameters:
      position - The vector representation of the position of the point to measure the distance to
      Returns:
      The signed distance of the mesh to the point. Values > 0 indicate the point is outside the mesh, values = 0 are points on the surface, and values < 0 are points inside the mesh.