Get point from curve intersection

Get point from curve intersection

Tripler123
Advocate Advocate
4,698 Views
4 Replies
Message 1 of 5

Get point from curve intersection

Tripler123
Advocate
Advocate

Hello, I'm trying to find a point that specifies the intersection of two lines. I have seen that there is a curve.Intersect (curve) that returns a SetComparisonResult. There is a possibility of finding an XYZ of that intersection or how you could do it.

 

 

 

 

 

public Result Execute(ExternalCommandData commandData,
                              ref string message,
                              ElementSet elements)
        {
            UIApplication uiApp = commandData.Application;
            UIDocument uiDoc = uiApp.ActiveUIDocument;
            Document doc = uiDoc.Document;

            // Conduit selection 
            ElementId conduitElementId = uiDoc.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element).ElementId;
            Element conduitElement = doc.GetElement(conduitElementId);

            // Get curve conduit
            LocationCurve conduitCurveLocation = conduitElement.Location as LocationCurve;
            Curve conduitCurve = conduitCurveLocation.Curve;

            // Get points conduit
            XYZ startConduitCurvePoint = conduitCurve.GetEndPoint(0);
            XYZ endConduitCurvePoint = conduitCurve.GetEndPoint(1);       

            // Beam selection 
            ElementId beamElementId = uiDoc.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element).ElementId;
            Element beamElement = doc.GetElement(beamElementId);

            // Get the beam inferior point y restar la mitad del diametro del elemento
            double beamInferiorPoint = beamElement.get_BoundingBox(doc.ActiveView).Min.Z - conduitElement.get_Parameter(BuiltInParameter.RBS_CONDUIT_DIAMETER_PARAM).AsDouble() /2;

            // Get curve beam 
            LocationCurve beamCurveLocation = beamElement.Location as LocationCurve;
            Curve beamCurve = beamCurveLocation.Curve;

            // Get points beam
            XYZ startBeamCurvePoint = beamCurve.GetEndPoint(0);
            XYZ endBeamCurvePoint = beamCurve.GetEndPoint(1);


            // Get points Conduit 
            XYZ startConduitPoint = new XYZ(startConduitCurvePoint.X, startConduitCurvePoint.Y, beamInferiorPoint);
            XYZ endConduitPoint = new XYZ(endConduitCurvePoint.X, endConduitCurvePoint.Y, beamInferiorPoint);

            // Get points Beam 
            XYZ startBeamPoint = new XYZ(startBeamCurvePoint.X, startBeamCurvePoint.Y, beamInferiorPoint);
            XYZ endBeamPoint = new XYZ(endBeamCurvePoint.X, endBeamCurvePoint.Y, beamInferiorPoint);


            // Line to get the point (Z is equal for two Lines)
            Line conduitLine = Line.CreateBound(startConduitPoint, endConduitPoint);
            Line beamLine = Line.CreateBound(startBeamCurvePoint, endBeamCurvePoint);

            // Get the intersection point
            conduitLine.Intersect(beamLine);// TODO: Get the point


            return Result.Succeeded;
        }

 

 

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

mhannonQ65N2
Collaborator
Collaborator
Accepted solution

Use the overload of Intersect that returns an array of intersection results as an out parameter.

 

// At top of file:
using System.Linq;

var intersects = conduitLine.Intersect(beamLine, out var intersections);
if(intersects == SetComparisonResult.Disjoint)
{
	// They don't intersect;
	return Result.Failed;
}
var intersection = intersections.Cast<IntersectionResult>().First();

var point = intersection.XYZPoint;

 

Message 3 of 5

Tripler123
Advocate
Advocate

Thanks, reading the information well I realized and solved it in the following way.

 

IntersectionResultArray intersectionResults = new IntersectionResultArray();

            List<XYZ> points = new List<XYZ>();

            SetComparisonResult result = conduitLine.Intersect(beamLine, out intersectionResults);

            if (result == SetComparisonResult.Overlap)
            {
                foreach (IntersectionResult intersectionResult in intersectionResults)
                {
                    XYZ point = intersectionResult.XYZPoint;
                    points.Add(point);
                }
            }

            TaskDialog.Show("title", points.Count.ToString() + $"{points[0]}");

 

0 Likes
Message 4 of 5

leungkahocityu
Community Visitor
Community Visitor

sir,

can apply to linked element?  such as linked wall

0 Likes
Message 5 of 5

praveen.cMXB2H
Enthusiast
Enthusiast

How can i find intersection point of wall and column.

 

@Tripler123 

0 Likes