How can we calculate the intersection between the plane and the penetrating line?

How can we calculate the intersection between the plane and the penetrating line?

휴엔
Participant Participant
4,733 Views
4 Replies
Message 1 of 5

How can we calculate the intersection between the plane and the penetrating line?

휴엔
Participant
Participant

Hello Everyone,
I have a question about the way to calculate intersection point.
We have four points which we know its coordinates.
and let's assume we can create plane with these points.
When there is a line penetrating the plane, I guess there are one intersection point which the plane and the line meet.

How can we calculate the coordinates of the intersection point?

Thank you in advance.

0 Likes
Accepted solutions (1)
4,734 Views
4 Replies
Replies (4)
Message 2 of 5

jeremytammik
Autodesk
Autodesk

You will only need three points to uniquely define the face, so the fourth point can actually be used to verify that all four are co-planar.

 

Calculating the intersection between a straight line and a plane is pretty easy, so the most efficient method to achieve this may possibly be to do it yourself:

 

 

If you prefer to use the official Revit API, you can refer to the Face.Intersect method taking a Curve argument:

  

  

I do not understand why you prefer to ask this question here instead fo searching for these results yourself.

  

It took me much longer to write them down than to find them.

  



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 5

jeremytammik
Autodesk
Autodesk
Accepted solution

I went ahead and implemented a line-plane intersection method for you in The Building Coder samples:

 

https://github.com/jeremytammik/the_building_coder_samples/blob/master/BuildingCoder/BuildingCoder/U...

 

Here is the code:

 

 

    /// <summary>
    /// Return the 3D intersection point between
    /// a line and a plane.
    /// https://forums.autodesk.com/t5/revit-api-forum/how-can-we-calculate-the-intersection-between-the-plane-and-the/m-p/9785834
    /// https://stackoverflow.com/questions/5666222/3d-line-plane-intersection
    /// Determine the point of intersection between 
    /// a plane defined by a point and a normal vector 
    /// and a line defined by a point and a direction vector.
    /// planePoint - A point on the plane.
    /// planeNormal - The normal vector of the plane.
    /// linePoint - A point on the line.
    /// lineDirection - The direction vector of the line.
    /// lineParameter - The intersection distance along the line.
    /// Return - The point of intersection between the 
    /// line and the plane, null if the line is parallel 
    /// to the plane.
    /// </summary>
    public static XYZ LinePlaneIntersection(
      Line line,
      Plane plane,
      out double lineParameter )
    {
      XYZ planePoint = plane.Origin;
      XYZ planeNormal = plane.Normal;
      XYZ linePoint = line.GetEndPoint( 0 );

      XYZ lineDirection = (line.GetEndPoint( 1 ) 
        - linePoint).Normalize();

      // Is the line parallel to the plane, i.e.,
      // perpendicular to the plane normal?

      if( IsZero( planeNormal.DotProduct( lineDirection ) ) )
      {
        lineParameter = double.NaN;
        return null;
      }

      lineParameter = (planeNormal.DotProduct( planePoint ) 
        - planeNormal.DotProduct( linePoint )) 
          / planeNormal.DotProduct( lineDirection );

      return linePoint + lineParameter * lineDirection;
    }

 

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 4 of 5

휴엔
Participant
Participant

Thank you for offering sample code. Actually I intended to find solution only with Revit Official API.

0 Likes
Message 5 of 5

NonicaTeam
Enthusiast
Enthusiast

Thanks @jeremytammik . It was really helpful for us!

0 Likes