rayoptics.util.misc_math module

miscellaneous functions for working with numpy vectors and floats

infinity_guard(x: float, big: float = 1000000000000.0) float[source]

Replace IEEE inf with a signed big number.

is_kinda_big(x: float, kinda_big: float = 100000000.0) bool[source]

Test for IEEE inf as well as any |x| > kinda_big

normalize(v)[source]

return normalized version of input vector v

distance_sqr_2d(pt0, pt1)[source]

return distance squared between 2d points pt0 and pt1

perpendicular_distance_2d(pt, pt1, pt2)[source]

return perpendicular distance of pt from the line between pt1 and pt2

perpendicular_to_radial(pt, pt2)[source]

return perpendicular distance of pt from the line between the origin and pt2

perpendicular_to_line(pt, pt1, pt2)[source]

return perpendicular distance of pt from the line between pt1 and pt2

perpendicular_from_origin(pt1, pt2)[source]

return perpendicular distance of the origin from the line between pt1 and pt2

projected_point_on_line(pt, pt1, pt2)[source]
projected_point_on_radial_line(pt, radial_pt)[source]
projected_point_on_radial_line_full(pt, radial_pt)[source]
rot_v1_into_v2(v1, v2)[source]

rotate v1 into v2 using equivalent angle rotation.

Compute a rotation matrix from v1 to v2. Take the cross product of the input vectors to get the rotation axis. The eqivalent angle rotation is equation 2.80 from Introduction to Robotics, 2nd ed, by John J Craig.

euler2opt(e)[source]

convert right-handed euler angles to optical design convention, i.e. alpha and beta are left-handed

euler2rot3d(euler)[source]

convert euler angle vector to a rotation matrix.

isanumber(a)[source]

returns true if input a can be converted to floating point number

transpose(mat)[source]

transposes a m x n input list and returns the result

circle_intersection_area(ra, rb, d)[source]

return the area of the intersection of 2 circles

Parameters:
  • ra – radius of first circle

  • rb – radius of second circle

  • d – separation of the circles’ centers of curvature

Returns:

area of the circle intersection

Weisstein, Eric W. “Circle-Circle Intersection.” From MathWorld–A Wolfram Web Resource.

compute_tangent_point_to_circle(CofC, r, pt)[source]

return the area of the intersection of 2 circles

Parameters:
  • CofC – center of curvature of circle (2d numpy array)

  • r – radius of circle

  • pt – 2d numpy array of point outside of circle

Returns:

the 2 tangent points for lines from pt to circle

gboffi. “How to find the equation of a line, tangent to a circle, that passes through a given external point.” StackExchange (version: 2019-05-30)