odak.raytracing
odak.raytracing
Provides necessary definitions for geometric optics. See "General Ray tracing procedure" from G.H. Spencerand M.V.R.K Murty for the theoratical explanation.
bring_plane_to_origin(point, plane, shape=[10.0, 10.0], center=[0.0, 0.0, 0.0], angles=[0.0, 0.0, 0.0], mode='XYZ')
¶
Definition to bring points back to reference origin with respect to a plane.
Parameters:
-
point–Point(s) to be tested. -
shape–Dimensions of the rectangle along X and Y axes. -
center–Center of the rectangle. -
angles–Rotation angle of the rectangle. -
mode–Rotation mode of the rectangle, for more see odak.tools.rotate_point and odak.tools.rotate_points.
Returns:
-
transformed_points(ndarray) –Point(s) that are brought back to reference origin with respect to given plane.
Source code in odak/raytracing/primitives.py
calculate_intersection_of_two_rays(ray0, ray1)
¶
Definition to calculate the intersection of two rays.
Parameters:
-
ray0–A ray. -
ray1–A ray.
Returns:
-
point(ndarray) –Point in X,Y,Z.
-
distances(ndarray) –Distances.
Source code in odak/raytracing/ray.py
center_of_triangle(triangle)
¶
Definition to calculate center of a triangle.
Parameters:
-
triangle–An array that contains three points defining a triangle (Mx3). It can also parallel process many triangles (NxMx3).
Source code in odak/raytracing/primitives.py
closest_point_to_a_ray(point, ray)
¶
Definition to calculate the point on a ray that is closest to given point.
Parameters:
-
point–Given point in X,Y,Z. -
ray–Given ray.
Returns:
-
closest_point(ndarray) –Calculated closest point.
Source code in odak/tools/vector.py
create_ray(x0y0z0, abg)
¶
Definition to create a ray.
Parameters:
-
x0y0z0–List that contains X,Y and Z start locations of a ray. -
abg–List that contaings angles in degrees with respect to the X,Y and Z axes.
Returns:
-
ray(ndarray) –Array that contains starting points and cosines of a created ray.
Source code in odak/raytracing/ray.py
create_ray_from_angles(point, angles, mode='XYZ')
¶
Definition to create a ray from a point and angles.
Parameters:
-
point–Point in X,Y and Z. -
angles–Angles with X,Y,Z axes in degrees. All zeros point Z axis. -
mode–Rotation mode determines ordering of the rotations at each axis. There are XYZ,YXZ ,ZXY and ZYX modes.
Returns:
-
ray(ndarray) –Created ray.
Source code in odak/raytracing/ray.py
create_ray_from_two_points(x0y0z0, x1y1z1)
¶
Definition to create a ray from two given points. Note that both inputs must match in shape.
Parameters:
-
x0y0z0–List that contains X,Y and Z start locations of a ray (3). It can also be a list of points as well (mx3). This is the starting point. -
x1y1z1–List that contains X,Y and Z ending locations of a ray (3). It can also be a list of points as well (mx3). This is the end point.
Returns:
-
ray(ndarray) –Array that contains starting points and cosines of a created ray.
Source code in odak/raytracing/ray.py
cylinder_function(point, cylinder)
¶
Definition of a cylinder function. Evaluate a point against a cylinder function. Inspired from https://mathworld.wolfram.com/Point-LineDistance3-Dimensional.html
Parameters:
-
cylinder–Cylinder parameters, XYZ center and radius. -
point–Point in XYZ.
Return
result : float Result of the evaluation. Zero if point is on sphere.
Source code in odak/raytracing/primitives.py
define_circle(center, radius, angles)
¶
Definition to describe a circle in a single variable packed form.
Parameters:
-
center–Center of a circle to be defined. -
radius–Radius of a circle to be defined. -
angles–Angular tilt of a circle.
Returns:
-
circle(list) –Single variable packed form.
Source code in odak/raytracing/primitives.py
define_cylinder(center, radius, rotation=[0.0, 0.0, 0.0])
¶
Definition to define a cylinder
Parameters:
-
center–Center of a cylinder in X,Y,Z. -
radius–Radius of a cylinder along X axis. -
rotation–Direction angles in degrees for the orientation of a cylinder.
Returns:
-
cylinder(ndarray) –Single variable packed form.
Source code in odak/raytracing/primitives.py
define_plane(point, angles=[0.0, 0.0, 0.0])
¶
Definition to generate a rotation matrix along X axis.
Parameters:
-
point–A point that is at the center of a plane. -
angles–Rotation angles in degrees.
Returns:
-
plane(ndarray) –Points defining plane.
Source code in odak/raytracing/primitives.py
define_sphere(center, radius)
¶
Definition to define a sphere.
Parameters:
-
center–Center of a sphere in X,Y,Z. -
radius–Radius of a sphere.
Returns:
-
sphere(ndarray) –Single variable packed form.
Source code in odak/raytracing/primitives.py
distance_between_two_points(point1, point2)
¶
Definition to calculate distance between two given points.
Parameters:
-
point1–First point in X,Y,Z. -
point2–Second point in X,Y,Z.
Returns:
-
distance(float) –Distance in between given two points.
Source code in odak/tools/vector.py
find_nearest_points(ray0, ray1)
¶
Find the nearest points on given rays with respect to the other ray.
Parameters:
-
ray0–A ray. -
ray1–A ray.
Returns:
-
c0(ndarray) –Closest point on ray0.
-
c1(ndarray) –Closest point on ray1.
Source code in odak/raytracing/ray.py
get_cylinder_normal(point, cylinder)
¶
Parameters:
-
point–Point on a cylinder defined in X,Y,Z.
Returns:
-
normal_vector(ndarray) –Normal vector.
Source code in odak/raytracing/boundary.py
get_sphere_normal(point, sphere)
¶
Definition to get a normal of a point on a given sphere.
Parameters:
-
point–Point on sphere in X,Y,Z. -
sphere–Center defined in X,Y,Z and radius.
Returns:
-
normal_vector(ndarray) –Normal vector.
Source code in odak/raytracing/boundary.py
get_triangle_normal(triangle, triangle_center=None)
¶
Definition to calculate surface normal of a triangle.
Parameters:
-
triangle–Set of points in X,Y and Z to define a planar surface (3,3). It can also be list of triangles (mx3x3). -
triangle_center(ndarray, default:None) –Center point of the given triangle. See odak.raytracing.center_of_triangle for more. In many scenarios you can accelerate things by precomputing triangle centers.
Returns:
-
normal(ndarray) –Surface normal at the point of intersection.
Source code in odak/raytracing/boundary.py
intersect_parametric(ray, parametric_surface, surface_function, surface_normal_function, target_error=1e-08, iter_no_limit=100000)
¶
Definition to intersect a ray with a parametric surface.
Parameters:
-
ray–Ray. -
parametric_surface–Parameters of the surfaces. -
surface_function–Function to evaluate a point against a surface. -
surface_normal_function(function) –Function to calculate surface normal for a given point on a surface. -
target_error–Target error that defines the precision. -
iter_no_limit–Maximum number of iterations.
Returns:
-
distance(float) –Propagation distance.
-
normal(ndarray) –Ray that defines a surface normal for the intersection.
Source code in odak/raytracing/boundary.py
intersect_w_circle(ray, circle)
¶
Definition to find intersection point of a ray with a circle. Returns False for each variable if the ray doesn't intersect with a given circle. Returns distance as zero if there isn't an intersection.
Parameters:
-
ray–A vector/ray. -
circle–A list that contains (0) Set of points in X,Y and Z to define plane of a circle, (1) circle center, and (2) circle radius.
Returns:
-
normal(ndarray) –Surface normal at the point of intersection.
-
distance(float) –Distance in between a starting point of a ray and the intersection point with a given triangle.
Source code in odak/raytracing/boundary.py
intersect_w_cylinder(ray, cylinder)
¶
Definition to intersect a ray with a cylinder.
Parameters:
-
ray–A ray definition. -
cylinder–A cylinder defined with a center in XYZ and radius of curvature.
Returns:
-
normal(ndarray) –A ray defining surface normal at the point of intersection.
-
distance(float) –Total optical propagation distance.
Source code in odak/raytracing/boundary.py
intersect_w_sphere(ray, sphere)
¶
Definition to intersect a ray with a sphere.
Parameters:
-
ray–A ray definition. -
sphere–A sphere defined with a center in XYZ and radius of curvature.
Returns:
-
normal(ndarray) –A ray defining surface normal at the point of intersection.
-
distance(float) –Total optical propagation distance.
Source code in odak/raytracing/boundary.py
intersect_w_surface(ray, points)
¶
Definition to find intersection point inbetween a surface and a ray. For more see: http://geomalgorithms.com/a06-_intersect-2.html
Parameters:
-
ray–A vector/ray. -
points–Set of points in X,Y and Z to define a planar surface.
Returns:
-
normal(ndarray) –Surface normal at the point of intersection.
-
distance(float) –Distance in between starting point of a ray with it's intersection with a planar surface.
Source code in odak/raytracing/boundary.py
intersect_w_triangle(ray, triangle)
¶
Definition to find intersection point of a ray with a triangle. Returns False for each variable if the ray doesn't intersect with a given triangle.
Parameters:
-
ray–A vector/ray (2 x 3). It can also be a list of rays (n x 2 x 3). -
triangle–Set of points in X,Y and Z to define a planar surface. It can also be a list of triangles (m x 3 x 3).
Returns:
-
normal(ndarray) –Surface normal at the point of intersection.
-
distance(float) –Distance in between a starting point of a ray and the intersection point with a given triangle.
Source code in odak/raytracing/boundary.py
intersection_kernel_for_parametric_surfaces(distance, ray, parametric_surface, surface_function)
¶
Definition for the intersection kernel when dealing with parametric surfaces.
Parameters:
-
distance–Distance. -
ray–Ray. -
parametric_surface(ndarray) –Array that defines a parametric surface. -
surface_function–Function to evaluate a point against a parametric surface.
Returns:
-
point(ndarray) –Location in X,Y,Z after propagation.
-
error(float) –Error.
Source code in odak/raytracing/boundary.py
is_it_on_triangle(pointtocheck, point0, point1, point2)
¶
Definition to check if a given point is inside a triangle. If the given point is inside a defined triangle, this definition returns True.
Parameters:
-
pointtocheck–Point to check. -
point0–First point of a triangle. -
point1–Second point of a triangle. -
point2–Third point of a triangle.
Source code in odak/raytracing/primitives.py
point_to_ray_distance(point, ray_point_0, ray_point_1)
¶
Definition to find point's closest distance to a line represented with two points.
Parameters:
-
point–Point to be tested. -
ray_point_0(ndarray) –First point to represent a line. -
ray_point_1(ndarray) –Second point to represent a line.
Returns:
-
distance(float) –Calculated distance.
Source code in odak/tools/vector.py
propagate_a_ray(ray, distance)
¶
Definition to propagate a ray at a certain given distance.
Parameters:
-
ray–A ray. -
distance–Distance.
Returns:
-
new_ray(ndarray) –Propagated ray.
Source code in odak/raytracing/ray.py
propagate_parametric_intersection_error(distance, error)
¶
Definition to propagate the error in parametric intersection to find the next distance to try.
Parameters:
-
distance–List that contains the new and the old distance. -
error–List that contains the new and the old error.
Returns:
-
distance(list) –New distance.
-
error(list) –New error.
Source code in odak/raytracing/boundary.py
reflect(input_ray, normal)
¶
Definition to reflect an incoming ray from a surface defined by a surface normal. Used method described in G.H. Spencer and M.V.R.K. Murty, "General Ray-Tracing Procedure", 1961.
Parameters:
-
input_ray–A vector/ray (2x3). It can also be a list of rays (nx2x3). -
normal–A surface normal (2x3). It also be a list of normals (nx2x3).
Returns:
-
output_ray(ndarray) –Array that contains starting points and cosines of a reflected ray.
Source code in odak/raytracing/boundary.py
rotate_point(point, angles=[0, 0, 0], mode='XYZ', origin=[0, 0, 0], offset=[0, 0, 0])
¶
Definition to rotate a given point. Note that rotation is always with respect to 0,0,0.
Parameters:
-
point–A point. -
angles–Rotation angles in degrees. -
mode–Rotation mode determines ordering of the rotations at each axis. There are XYZ,YXZ,ZXY and ZYX modes. -
origin–Reference point for a rotation. -
offset–Shift with the given offset.
Returns:
-
result(ndarray) –Result of the rotation
-
rotx(ndarray) –Rotation matrix along X axis.
-
roty(ndarray) –Rotation matrix along Y axis.
-
rotz(ndarray) –Rotation matrix along Z axis.
Source code in odak/tools/transformation.py
rotate_points(points, angles=[0, 0, 0], mode='XYZ', origin=[0, 0, 0], offset=[0, 0, 0])
¶
Definition to rotate points.
Parameters:
-
points–Points. -
angles–Rotation angles in degrees. -
mode–Rotation mode determines ordering of the rotations at each axis. There are XYZ,YXZ,ZXY and ZYX modes. -
origin–Reference point for a rotation. -
offset–Shift with the given offset.
Returns:
-
result(ndarray) –Result of the rotation
Source code in odak/tools/transformation.py
same_side(p1, p2, a, b)
¶
Definition to figure which side a point is on with respect to a line and a point. See http://www.blackpawn.com/texts/pointinpoly/ for more. If p1 and p2 are on the sameside, this definition returns True.
Parameters:
-
p1–Point(s) to check. -
p2–This is the point check against. -
a–First point that forms the line. -
b–Second point that forms the line.
Source code in odak/tools/vector.py
sphere_function(point, sphere)
¶
Definition of a sphere function. Evaluate a point against a sphere function.
Parameters:
-
sphere–Sphere parameters, XYZ center and radius. -
point–Point in XYZ.
Return
result : float Result of the evaluation. Zero if point is on sphere.
Source code in odak/raytracing/primitives.py
get_cylinder_normal(point, cylinder)
¶
Parameters:
-
point–Point on a cylinder defined in X,Y,Z.
Returns:
-
normal_vector(ndarray) –Normal vector.
Source code in odak/raytracing/boundary.py
get_sphere_normal(point, sphere)
¶
Definition to get a normal of a point on a given sphere.
Parameters:
-
point–Point on sphere in X,Y,Z. -
sphere–Center defined in X,Y,Z and radius.
Returns:
-
normal_vector(ndarray) –Normal vector.
Source code in odak/raytracing/boundary.py
get_triangle_normal(triangle, triangle_center=None)
¶
Definition to calculate surface normal of a triangle.
Parameters:
-
triangle–Set of points in X,Y and Z to define a planar surface (3,3). It can also be list of triangles (mx3x3). -
triangle_center(ndarray, default:None) –Center point of the given triangle. See odak.raytracing.center_of_triangle for more. In many scenarios you can accelerate things by precomputing triangle centers.
Returns:
-
normal(ndarray) –Surface normal at the point of intersection.
Source code in odak/raytracing/boundary.py
intersect_parametric(ray, parametric_surface, surface_function, surface_normal_function, target_error=1e-08, iter_no_limit=100000)
¶
Definition to intersect a ray with a parametric surface.
Parameters:
-
ray–Ray. -
parametric_surface–Parameters of the surfaces. -
surface_function–Function to evaluate a point against a surface. -
surface_normal_function(function) –Function to calculate surface normal for a given point on a surface. -
target_error–Target error that defines the precision. -
iter_no_limit–Maximum number of iterations.
Returns:
-
distance(float) –Propagation distance.
-
normal(ndarray) –Ray that defines a surface normal for the intersection.
Source code in odak/raytracing/boundary.py
intersect_w_circle(ray, circle)
¶
Definition to find intersection point of a ray with a circle. Returns False for each variable if the ray doesn't intersect with a given circle. Returns distance as zero if there isn't an intersection.
Parameters:
-
ray–A vector/ray. -
circle–A list that contains (0) Set of points in X,Y and Z to define plane of a circle, (1) circle center, and (2) circle radius.
Returns:
-
normal(ndarray) –Surface normal at the point of intersection.
-
distance(float) –Distance in between a starting point of a ray and the intersection point with a given triangle.
Source code in odak/raytracing/boundary.py
intersect_w_cylinder(ray, cylinder)
¶
Definition to intersect a ray with a cylinder.
Parameters:
-
ray–A ray definition. -
cylinder–A cylinder defined with a center in XYZ and radius of curvature.
Returns:
-
normal(ndarray) –A ray defining surface normal at the point of intersection.
-
distance(float) –Total optical propagation distance.
Source code in odak/raytracing/boundary.py
intersect_w_sphere(ray, sphere)
¶
Definition to intersect a ray with a sphere.
Parameters:
-
ray–A ray definition. -
sphere–A sphere defined with a center in XYZ and radius of curvature.
Returns:
-
normal(ndarray) –A ray defining surface normal at the point of intersection.
-
distance(float) –Total optical propagation distance.
Source code in odak/raytracing/boundary.py
intersect_w_surface(ray, points)
¶
Definition to find intersection point inbetween a surface and a ray. For more see: http://geomalgorithms.com/a06-_intersect-2.html
Parameters:
-
ray–A vector/ray. -
points–Set of points in X,Y and Z to define a planar surface.
Returns:
-
normal(ndarray) –Surface normal at the point of intersection.
-
distance(float) –Distance in between starting point of a ray with it's intersection with a planar surface.
Source code in odak/raytracing/boundary.py
intersect_w_triangle(ray, triangle)
¶
Definition to find intersection point of a ray with a triangle. Returns False for each variable if the ray doesn't intersect with a given triangle.
Parameters:
-
ray–A vector/ray (2 x 3). It can also be a list of rays (n x 2 x 3). -
triangle–Set of points in X,Y and Z to define a planar surface. It can also be a list of triangles (m x 3 x 3).
Returns:
-
normal(ndarray) –Surface normal at the point of intersection.
-
distance(float) –Distance in between a starting point of a ray and the intersection point with a given triangle.
Source code in odak/raytracing/boundary.py
intersection_kernel_for_parametric_surfaces(distance, ray, parametric_surface, surface_function)
¶
Definition for the intersection kernel when dealing with parametric surfaces.
Parameters:
-
distance–Distance. -
ray–Ray. -
parametric_surface(ndarray) –Array that defines a parametric surface. -
surface_function–Function to evaluate a point against a parametric surface.
Returns:
-
point(ndarray) –Location in X,Y,Z after propagation.
-
error(float) –Error.
Source code in odak/raytracing/boundary.py
propagate_parametric_intersection_error(distance, error)
¶
Definition to propagate the error in parametric intersection to find the next distance to try.
Parameters:
-
distance–List that contains the new and the old distance. -
error–List that contains the new and the old error.
Returns:
-
distance(list) –New distance.
-
error(list) –New error.
Source code in odak/raytracing/boundary.py
reflect(input_ray, normal)
¶
Definition to reflect an incoming ray from a surface defined by a surface normal. Used method described in G.H. Spencer and M.V.R.K. Murty, "General Ray-Tracing Procedure", 1961.
Parameters:
-
input_ray–A vector/ray (2x3). It can also be a list of rays (nx2x3). -
normal–A surface normal (2x3). It also be a list of normals (nx2x3).
Returns:
-
output_ray(ndarray) –Array that contains starting points and cosines of a reflected ray.
Source code in odak/raytracing/boundary.py
bring_plane_to_origin(point, plane, shape=[10.0, 10.0], center=[0.0, 0.0, 0.0], angles=[0.0, 0.0, 0.0], mode='XYZ')
¶
Definition to bring points back to reference origin with respect to a plane.
Parameters:
-
point–Point(s) to be tested. -
shape–Dimensions of the rectangle along X and Y axes. -
center–Center of the rectangle. -
angles–Rotation angle of the rectangle. -
mode–Rotation mode of the rectangle, for more see odak.tools.rotate_point and odak.tools.rotate_points.
Returns:
-
transformed_points(ndarray) –Point(s) that are brought back to reference origin with respect to given plane.
Source code in odak/raytracing/primitives.py
center_of_triangle(triangle)
¶
Definition to calculate center of a triangle.
Parameters:
-
triangle–An array that contains three points defining a triangle (Mx3). It can also parallel process many triangles (NxMx3).
Source code in odak/raytracing/primitives.py
cylinder_function(point, cylinder)
¶
Definition of a cylinder function. Evaluate a point against a cylinder function. Inspired from https://mathworld.wolfram.com/Point-LineDistance3-Dimensional.html
Parameters:
-
cylinder–Cylinder parameters, XYZ center and radius. -
point–Point in XYZ.
Return
result : float Result of the evaluation. Zero if point is on sphere.
Source code in odak/raytracing/primitives.py
define_circle(center, radius, angles)
¶
Definition to describe a circle in a single variable packed form.
Parameters:
-
center–Center of a circle to be defined. -
radius–Radius of a circle to be defined. -
angles–Angular tilt of a circle.
Returns:
-
circle(list) –Single variable packed form.
Source code in odak/raytracing/primitives.py
define_cylinder(center, radius, rotation=[0.0, 0.0, 0.0])
¶
Definition to define a cylinder
Parameters:
-
center–Center of a cylinder in X,Y,Z. -
radius–Radius of a cylinder along X axis. -
rotation–Direction angles in degrees for the orientation of a cylinder.
Returns:
-
cylinder(ndarray) –Single variable packed form.
Source code in odak/raytracing/primitives.py
define_plane(point, angles=[0.0, 0.0, 0.0])
¶
Definition to generate a rotation matrix along X axis.
Parameters:
-
point–A point that is at the center of a plane. -
angles–Rotation angles in degrees.
Returns:
-
plane(ndarray) –Points defining plane.
Source code in odak/raytracing/primitives.py
define_sphere(center, radius)
¶
Definition to define a sphere.
Parameters:
-
center–Center of a sphere in X,Y,Z. -
radius–Radius of a sphere.
Returns:
-
sphere(ndarray) –Single variable packed form.
Source code in odak/raytracing/primitives.py
is_it_on_triangle(pointtocheck, point0, point1, point2)
¶
Definition to check if a given point is inside a triangle. If the given point is inside a defined triangle, this definition returns True.
Parameters:
-
pointtocheck–Point to check. -
point0–First point of a triangle. -
point1–Second point of a triangle. -
point2–Third point of a triangle.
Source code in odak/raytracing/primitives.py
sphere_function(point, sphere)
¶
Definition of a sphere function. Evaluate a point against a sphere function.
Parameters:
-
sphere–Sphere parameters, XYZ center and radius. -
point–Point in XYZ.
Return
result : float Result of the evaluation. Zero if point is on sphere.
Source code in odak/raytracing/primitives.py
calculate_intersection_of_two_rays(ray0, ray1)
¶
Definition to calculate the intersection of two rays.
Parameters:
-
ray0–A ray. -
ray1–A ray.
Returns:
-
point(ndarray) –Point in X,Y,Z.
-
distances(ndarray) –Distances.
Source code in odak/raytracing/ray.py
create_ray(x0y0z0, abg)
¶
Definition to create a ray.
Parameters:
-
x0y0z0–List that contains X,Y and Z start locations of a ray. -
abg–List that contaings angles in degrees with respect to the X,Y and Z axes.
Returns:
-
ray(ndarray) –Array that contains starting points and cosines of a created ray.
Source code in odak/raytracing/ray.py
create_ray_from_angles(point, angles, mode='XYZ')
¶
Definition to create a ray from a point and angles.
Parameters:
-
point–Point in X,Y and Z. -
angles–Angles with X,Y,Z axes in degrees. All zeros point Z axis. -
mode–Rotation mode determines ordering of the rotations at each axis. There are XYZ,YXZ ,ZXY and ZYX modes.
Returns:
-
ray(ndarray) –Created ray.
Source code in odak/raytracing/ray.py
create_ray_from_two_points(x0y0z0, x1y1z1)
¶
Definition to create a ray from two given points. Note that both inputs must match in shape.
Parameters:
-
x0y0z0–List that contains X,Y and Z start locations of a ray (3). It can also be a list of points as well (mx3). This is the starting point. -
x1y1z1–List that contains X,Y and Z ending locations of a ray (3). It can also be a list of points as well (mx3). This is the end point.
Returns:
-
ray(ndarray) –Array that contains starting points and cosines of a created ray.
Source code in odak/raytracing/ray.py
find_nearest_points(ray0, ray1)
¶
Find the nearest points on given rays with respect to the other ray.
Parameters:
-
ray0–A ray. -
ray1–A ray.
Returns:
-
c0(ndarray) –Closest point on ray0.
-
c1(ndarray) –Closest point on ray1.
Source code in odak/raytracing/ray.py
propagate_a_ray(ray, distance)
¶
Definition to propagate a ray at a certain given distance.
Parameters:
-
ray–A ray. -
distance–Distance.
Returns:
-
new_ray(ndarray) –Propagated ray.