How to get the Intersection between a curve and a plane

How to get the Intersection between a curve and a plane

Anonymous
Not applicable
7,067 Views
8 Replies
Message 1 of 9

How to get the Intersection between a curve and a plane

Anonymous
Not applicable

Hi all, I have been searching this for a while. How to determine the intersection XYZ point between a curve and a plane? The Revit API provides method to get the intersection point between a face and a curve. But there does not seem exist a way to create a face from a plane. I do not have a solid to extract the face from. All I have is a curve and a plane.

This should be a basic tool for geometry analysis. Am I missing something?

Thanks

 

0 Likes
7,068 Views
8 Replies
Replies (8)
Message 2 of 9

aignatovich
Advisor
Advisor

Hi! There is no such API, but your task could be solved in various ways.

 

For example, if you have a Plane object you can create a Transform, using its Origin, XVec, YVec and Normal.

 

Using Transform.Inverse you can get line origin and direction in the coordinate system of your plane. The line equation is (x, y, z) = (ox, oy, oz) + t(nx, ny, nz), where ox, oy, oz - plane origin and nx, ny, nz - normal coordinates. An intersection point z coordinate is zero. You can easily find X and Y, just solve this equation system. So, if the equation system has a solution, use Transform.OfPoint(new XYZ(x, y, 0)) to switch back to the model coordinate system

Message 3 of 9

aignatovich
Advisor
Advisor

Oh. The line equation is (x, y, z) = (ox, oy, oz) + t(dx, dy, dz), where ox, oy, oz - line origin and dx, dy, dz - line direction coordinates of course, sorry

Message 4 of 9

Anonymous
Not applicable

 

Thanks for your reply. The algorithm seems a bit complex. I hope Autodesk will add the API in the future. For the time being, I just create a big cubic solid and use the plane to cut the solid to get a face, and then I can get the intersection points.

 

0 Likes
Message 5 of 9

BardiaJahan
Advocate
Advocate

If the curve is a line, there is an alternative approach which may be easier to implement with Revit API. For a given line and a plane, let's call the intersection point P. Now if you project the line onto the plane, the result passes through P.

So you can easily project two points of the line onto the plane -Plane.Project() - create another line that passes through those two points - Line.Create(Un)bound() - and the last thing you have to do is to find the intersection of those two lines - Line.Intersect()

 

Something like this:

// Plane plane
// Line line
UV uv1, uv2 = new UV();

plane.Project(line.Origin, out uv1, out double d);
plane.Project(line.Origin + line.Direction, out uv2, out double b);

XYZ xyz1 = plane.Origin + (uv1.U * plane.XVec) + (uv1.V * plane.YVec);
XYZ xyz2 = plane.Origin + (uv2.U * plane.XVec) + (uv2.V * plane.YVec);

Line projectedLine = Line.CreateUnbound(xyz1, xyz2 - xyz1);

IntersectionResultArray iResult = new IntersectionResultArray();
if (line.Intersect(projectedLine, out iResult) != SetComparisonResult.Disjoint) return iResult.get_Item(0).XYZPoint;
Message 6 of 9

stever66
Advisor
Advisor

As another possible solution route - can you create a solid from your plane, get the face, find the intersection points, and then delete the solid?

 

i know it sounds like a lot of extra work, but code wise, it might be pretty simple.

0 Likes
Message 8 of 9

Vlastro
Explorer
Explorer

Hi, BardiaJahan! Your method is cool! But I've got an exception, if input projected line is normal to plane. Here is my little change of your code:

public XYZ GetPlaneAndLineIntersection(Plane plane, Line line)
{
UV uv1, uv2 = new UV();

plane.Project(line.Origin, out uv1, out double d);
plane.Project(line.Origin + line.Direction, out uv2, out double b);

XYZ xyz1 = plane.Origin + (uv1.U * plane.XVec) + (uv1.V * plane.YVec);
XYZ xyz2 = plane.Origin + (uv2.U * plane.XVec) + (uv2.V * plane.YVec);

if (xyz1.IsAlmostEqualTo(xyz2))
{
return xyz1;
}

Line projectedLine = Line.CreateUnbound(xyz1, xyz2 - xyz1);

IntersectionResultArray iResult = new IntersectionResultArray();
if (line.Intersect(projectedLine, out iResult) != SetComparisonResult.Disjoint)
{
return iResult.get_Item(0).XYZPoint;
}
return null;
}

 

vlastro
Message 9 of 9

BardiaJahan
Advocate
Advocate

Beautiful! 

0 Likes