module: common.geom

Utilities for handling 3D vectors, 2D intersections and geometry

common.geom.abs_dot(a, b)

Return \(|a \dot b|\)

common.geom.axis_angle_matrix3(unit, theta)

Return the 3x3 rotation matrix around an arbitrary unit vector

common.geom.bbox_point_intersects(bbox, a)
common.geom.bbox_segment_intersects(bbox, a, b)

Return true if the bbox contains or partially intersects segment a.

common.geom.bbox_svg_transform(box)

SVG transform to zoom into bbox

common.geom.complete_vector_triplets(vectors, tolerance_dot=0.90630778703)

Completes any missing orthogonal triplets in a set of unit vectors. Returns the completed set of vectors.

common.geom.complex_polygon_centroid(vertices, triangles)
common.geom.construct_all_uvn_frames(vectors, flip_to_match_image=True)
common.geom.construct_uvn_frame(n, u, b=None, flip_to_match_image=True)

Returns an orthonormal 3x3 frame from a normal and one in-plane vector

common.geom.homo_line(a, b)

Return the homogenous equation of a line passing through a and b, i.e. [ax, ay, 1] cross [bx, by, 1]

common.geom.line_ccw(a, b, p)

Return which side p is on with respect to line ab.

common.geom.matrix_to_column_list(m)

Expand a matrix to a list, column-major order

common.geom.most_orthogonal_vector(v, vectors, tolerance_dot=1.0)

Returns the most orthogonal vector to v, from the set w. The vector must also be at least as orthogonal as the tolerance. If nothing is that orthogonal, None is returned. All vectors are assumed to be unit length.

common.geom.most_parallel_vector(v, vectors, tolerance_dot=0.0)

Returns the most parallel vector to v, from the set w. The vector must also be at least as parallel as the tolerance. If nothing is that parallel, None is returned. All vectors are assumed to be unit length.

common.geom.normalized(v)

Normalize an nd vector

common.geom.normalized_cross(a, b)

3D cross product

common.geom.orthogonalize_matrix(m)

Returns the closest orthogonal matrix to m (closest as measured by Frobenius norm)

common.geom.rotation_matrix3(axis, theta)

Return the 3x3 rotation matrix around the specified axis (0, 1, or 2)

common.geom.same_side_product(p, q, a, b)

Return > 0 if p and q lie on the same side of line ab, 0 if both on the line, and < 0 if on opposite sides of the line.

common.geom.segment_point_distance_sq(x1, y1, x2, y2, px, py)

Return the distance from segment (x1, y1, x2, y2) to point (px, py)

common.geom.segment_segment_intersects(a, b, c, d)

Return whether segment ab intersects cd where a, b, c, d are point tuples.

common.geom.simplify_polyline_epsilon(points, epsilon)

Simplify a polyline based on the Ramer-Douglas-Peucker Algorithm (http://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm) Implementation adapted from: http://stackoverflow.com/questions/2573997/reduce-number-of-points-in-line

common.geom.sphere_to_unit(v)

Convert (theta, phi) to (x, y, z)

common.geom.triangle_area(a, b, c)

Return the area of the triangle defined by [a, b, c], where each vertex contains floats [x, y]

common.geom.triangle_point_intersects(a, b, c, s)

Return whether point s intersects triangle a,b,c.

common.geom.triangle_segment_intersects(t0, t1, t2, p0, p1)

Return whether line p0,p1 intersects triangle t0,t1,t2. Containment counts as intersection.

common.geom.triangles_segments_intersections_only(vertices, segments, triangles, query_segments)

Return the indices of the query segments that intersect any of the triangles, but none of the segments. vertices are a list of point tuples, segments are lists of tuples of indices into vertices, and triangles are lists of tuples of indices into vertices. query_segments are a list of point tuples [((x1, y1), (x2, y2)), ...].

common.geom.unit_to_sphere(v)

Convert (x, y, z) to (theta, phi)

common.geom.vanishing_line(n, focal)

Returns the equation of the vanishing line given a normal