Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
ab = subtract_vectors(b, a)
cosa = dot_vectors(n, ab)
if fabs(cosa) <= tol:
# if the dot product (cosine of the angle between segment and plane)
# is close to zero the line and the normal are almost perpendicular
# hence there is no intersection
return None
# based on the ratio = -dot_vectors(n, ab) / dot_vectors(n, oa)
# there are three scenarios
# 1) 0.0 < ratio < 1.0: the intersection is between a and b
# 2) ratio < 0.0: the intersection is on the other side of a
# 3) ratio > 1.0: the intersection is on the other side of b
oa = subtract_vectors(a, o)
ratio = - dot_vectors(n, oa) / cosa
ab = scale_vector(ab, ratio)
return add_vectors(a, ab)
def _normal_face(face):
u = subtract_vectors(points[face[1]], points[face[0]])
v = subtract_vectors(points[face[-1]], points[face[0]])
return cross_vectors(u, v)
Normal vector of the projection plane.
perspective : list of float
Perspective of the projection.
Examples
--------
>>> point = [0, 0, 0]
>>> normal = [0, 0, 1]
>>> perspective = [1, 1, 0]
>>> P = matrix_from_perspective_projection(point, normal, perspective)
"""
T = identity_matrix(4)
normal = normalize_vector(normal)
T[0][0] = T[1][1] = T[2][2] = dot_vectors(subtract_vectors(perspective, point), normal)
for j in range(3):
for i in range(3):
T[i][j] -= perspective[i] * normal[j]
T[0][3], T[1][3], T[2][3] = scale_vector(perspective, dot_vectors(point, normal))
for i in range(3):
T[3][i] -= normal[i]
T[3][3] = dot_vectors(perspective, normal)
return T
XYZ coordinates of the two points marking the shortest distance between the lines.
If the lines intersect, these two points are identical.
If the lines are skewed and thus only have an apparent intersection, the two
points are different.
If the lines are parallel, the return value is [None, None].
Examples
--------
>>>
"""
a, b = l1
c, d = l2
ab = subtract_vectors(b, a)
cd = subtract_vectors(d, c)
n = cross_vectors(ab, cd)
n1 = normalize_vector(cross_vectors(ab, n))
n2 = normalize_vector(cross_vectors(cd, n))
plane_1 = (a, n1)
plane_2 = (c, n2)
i1 = intersection_line_plane(l1, plane_2, tol=tol)
i2 = intersection_line_plane(l2, plane_1, tol=tol)
return i1, i2
point_xyplane : point
A point within the xy-plane of the frame.
Returns
-------
Frame
The constructed frame.
Examples
--------
>>> from compas.geometry import Frame
>>> f = Frame.from_points([1, 1, 1], [2, 4, 5], [4, 2, 3])
"""
xaxis = subtract_vectors(point_xaxis, point)
xyvec = subtract_vectors(point_xyplane, point)
yaxis = cross_vectors(cross_vectors(xaxis, xyvec), xaxis)
return cls(point, xaxis, yaxis)
-------
list
XYZ coordinates of the projected point.
Notes
-----
For more info, see [1]_.
References
----------
.. [1] Wiki Books. *Linear Algebra/Orthogonal Projection Onto a Line*.
Available at: https://en.wikibooks.org/wiki/Linear_Algebra/Orthogonal_Projection_Onto_a_Line.
"""
a, b = line
ab = subtract_vectors(b, a)
ap = subtract_vectors(point, a)
c = vector_component(ap, ab)
return add_vectors(a, c)
A sequence of XYZ coordinates of two 3D points representing two points on the line.
l2 : tuple
A sequence of XYZ coordinates of two 3D points representing two points on the line.
tol : float, optional
A tolerance for intersection verification. Default is ``1e-6``.
Returns
--------
bool
``True``if the lines intersect in one point.
``False`` if the lines are skew, parallel or lie on top of each other.
"""
a, b = l1
c, d = l2
e1 = normalize_vector(subtract_vectors(b, a))
e2 = normalize_vector(subtract_vectors(d, c))
# check for parallel lines
if abs(dot_vectors(e1, e2)) > 1.0 - tol:
return False
# check for intersection
d_vector = cross_vectors(e1, e2)
if dot_vectors(d_vector, subtract_vectors(c, a)) == 0:
return True
return False
Returns
-------
float
Distance bewteen a and b.
Examples
--------
>>> distance_point_point([0.0, 0.0, 0.0], [2.0, 0.0, 0.0])
2.0
See Also
--------
distance_point_point_xy
"""
ab = subtract_vectors(b, a)
return length_vector(ab)