Package geometries

Class Sphere

java.lang.Object
geometries.Geometry
geometries.Sphere
All Implemented Interfaces:
Intersectible

public class Sphere
extends Geometry
This represents a sphere. A sphere is described by a center Point and a positive radius.
  • Field Summary

    Fields inherited from class geometries.Geometry

    material
  • Constructor Summary

    Constructors
    Constructor Description
    Sphere​(Material material, Point center, double radius)
    Constructs a sphere from a given center point and a radius.
  • Method Summary

    Modifier and Type Method Description
    geometries.Boundary boundary()
    Get the Boundary of this intersectible.
    java.util.List<Intersection> intersect​(LineSegment line)
    Calculates all the intersections between a given LineSegment and this object.
    NormalizedVector normal​(Point p)
    Returns normal to the sphere at given point.

    Methods inherited from class geometries.Geometry

    intersection

    Methods inherited from class java.lang.Object

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

    • Sphere

      public Sphere​(Material material, Point center, double radius)
      Constructs a sphere from a given center point and a radius.
      Parameters:
      material - The Material the sphere is made from.
      center - A Point representing the center of the circle.
      radius - A positive number representing the radius. If given a negative number will be assumed to be positive.
      Throws:
      java.lang.IllegalArgumentException - if the radius is zero.
  • Method Details

    • normal

      public NormalizedVector normal​(Point p)
      Returns normal to the sphere at given point.
      Specified by:
      normal in class Geometry
      Parameters:
      p - The point to get normal at. This point is assumed to be on the surface of the circle. If it's not then it is undefined behavior.
      Returns:
      A NormalizedVector perpendicular to the surface of the shape at the given Point.
      Throws:
      ZeroVectorException - if p is the center of the sphere.
    • intersect

      public java.util.List<Intersection> intersect​(LineSegment line)
      Description copied from interface: Intersectible
      Calculates all the intersections between a given LineSegment and this object.
      Parameters:
      line - The LineSegment to check for intersections.
      Returns:
      A list of all the intersections with the given LineSegment.
    • boundary

      public geometries.Boundary boundary()
      Description copied from interface: Intersectible
      Get the Boundary of this intersectible.
      Returns:
      The bounding box of this intersectible.