Geometry

Module collecting a number of renderable objects. Geometry is an abstract base class defining the interface and Sphere and Plane are concrete, renderable implementatons.

class padvinder.geometry.Geometry(material=Material(color=[0.5 0.5 0.5]))[source]

Bases: object

Baseclass for geometry. Either implicitly (eg. spheres and planes) or explicitly via triangles.

Parameters:material (padvinder.material.Material) – A material specifies how the geometry surface interacts with light rays

Examples

>>> Geometry()
Geometry(Material(color=[0.5, 0.5, 0.5]))
material

Returns the material of this geometry instance.

intersect(ray)[source]

Given a ray, intersect it with this geometry instance and returns the distance t of ray position to intersection point (so that ray.point(t) is the intersection point) If no intersection occurs +inf is returned.

Parameters:ray (Ray) – the ray to be tested for intersection
Returns:in (0, +inf]
Return type:float
Raises:NotImplemented – because this is an abstract base class

Examples

>>> a = Sphere()
>>> r = Ray()
>>> a.intersect(r)
1.0
normal(x)[source]

Given a point on the surface of the geometry instance and returns the surface normal at that point.

Parameters:x (numpy.ndarray_like) – point on the geometry instance
Returns:n – normal vector of the geometry surface at this point
Return type:numpy.ndarray_like
Raises:NotImplemented – because this is an abstract base class
class padvinder.geometry.Sphere(material=Material(color=[0.5 0.5 0.5]), position=(0, 0, 0), radius=1)[source]

Bases: padvinder.geometry.Geometry

An implicitly modeled sphere is given by:
LA.norm(position - x) - r = 0, where position is the center of the sphere, x is a point on the surface of the sphere and r is the radius.
Parameters:
  • material (padvinder.material.Material) – A material specifies how the geometry surface interacts with light rays
  • position (numpy.ndarray_like) – position of the sphere’s center in world coordinates
  • radius (number) – radius of the sphere

Examples

>>> Sphere() #unitsphere
Sphere(Material(color=[0.5, 0.5, 0.5]),
                position=[0.0, 0.0, 0.0],
                radius=1)
position

Returns the position of the center of the sphere.

radius

Returns the radius of the sphere.

intersect(ray)[source]

Given a ray, intersect it with this sphere instance and returns the distance t of ray position to intersection point (so that ray.get_point(t) is the intersection point) If no intersection occurs +inf is returned.

Parameters:ray (Ray) – the ray to be tested for intersections
Returns:number in (0, +inf]
Return type:float
normal(x)[source]

Given a point on the surface of the sphere instance and returns the surface normal at that point.

Parameters:x (numpy.ndarray_like) – point on the geometry instance
Returns:normal – normal vector of the geometry surface at this point
Return type:numpy.ndarray_like
class padvinder.geometry.Plane(material=Material(color=[0.5 0.5 0.5]), position=(0, 0, 0), normal=(0, 1, 0))[source]

Bases: padvinder.geometry.Geometry

An implicitly modelled plane is given by n * x - d = 0, where n is the normal vector, x is a point in world coordinates, d is a number and n * x is the dot product of two vectors.

Parameters:
  • material (padvinder.material.Material) – material instance
  • position (numpy.ndarray_like) – the ‘origin’ of the plane - any point in the world the plane passes through
  • normal (numpy.ndarray_like) – the normalised vector thats orthogonal to the plane

Examples

>>> Plane()   # equivalent to ...
>>> Plane(Material(), (0, 0, 0), (1, 0, 0))
Plane(Material(color=[1., 1., 1.]), position=(0, 0, 0), normal=(0, 1, 0))
position

Returns the position of the plane.

intersect(ray)[source]

Given a ray Returns the value t so that ray.get_point(t) is the closest intersection point or +inf if the plane is not hit.

Parameters:ray (Ray) – the ray to be tested for intersections
Returns:
Return type:number in (0, +inf]

Examples

>>> a = plane()
>>> r = ray()
>>> a.intersect(r)
1.0
normal(x)[source]

Given a point on the surface of the plane, returns the surface normal at that point.

Parameters:x (numpy.ndarray_like) – point on the plane instance
Returns:normal – normal vector of the plane surface at this point
Return type:numpy.ndarray_like