3D Line-Plane Intersection

后端 未结 8 1905
-上瘾入骨i
-上瘾入骨i 2020-11-29 21:51

If given a line (represented by either a vector or two points on the line) how do I find the point at which the line intersects a plane? I\'ve found loads of resources on th

8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-29 22:25

    Using numpy and python:

    #Based on http://geomalgorithms.com/a05-_intersect-1.html
    from __future__ import print_function
    import numpy as np
    
    epsilon=1e-6
    
    #Define plane
    planeNormal = np.array([0, 0, 1])
    planePoint = np.array([0, 0, 5]) #Any point on the plane
    
    #Define ray
    rayDirection = np.array([0, -1, -1])
    rayPoint = np.array([0, 0, 10]) #Any point along the ray
    
    ndotu = planeNormal.dot(rayDirection) 
    
    if abs(ndotu) < epsilon:
        print ("no intersection or line is within plane")
    
    w = rayPoint - planePoint
    si = -planeNormal.dot(w) / ndotu
    Psi = w + si * rayDirection + planePoint
    
    print ("intersection at", Psi)
    

提交回复
热议问题