Curve intersect

Curve intersect

stefano.cartaKGT96
Advocate Advocate
1,349 Views
6 Replies
Message 1 of 7

Curve intersect

stefano.cartaKGT96
Advocate
Advocate

Hi Guys..

 

I have a list of xyz point by a txt file.

I import it and I create a CurveLoop

Then I have to check the intersection of this curve with a Line and find intersection point coordinates.

i use this code, but I receive an exception:

System.InvalidCastException: 'unable to casttype  'Autodesk.Revit.DB.Line' on type 'System.Collections.Generic.IEnumerable`1[Autodesk.Revit.DB.Curve]'.' on the intersect line code

where am i wrong?

Thanks

Stefano

 

 Dim CurvaAsse3D As New CurveLoop
 Dim CurvaAsse2D As New CurveLoop
            For xx = 0 To listaPuntiAsse.Count - 1
                If xx <> listaPuntiAsse.Count - 1 Then
                    Dim Linea As Line = Line.CreateBound(listaPuntiAsse(xx), listaPuntiAsse(xx + 1))
                    Dim Linea2d As Line = Line.CreateBound(listaPuntiAsse2D(xx), listaPuntiAsse2D(xx + 1))
                    CurvaAsse3D.Append(Linea)
                    CurvaAsse2D.Append(Linea2d)
                End If
            Next
Dim lineaprova As Line = Line.CreateBound(InternalPoint4, InternalPoint1)
Dim ptinter As XYZ = CurvaAsse3D.Intersect(lineaprova)

 

 

 

0 Likes
Accepted solutions (1)
1,350 Views
6 Replies
Replies (6)
Message 2 of 7

RPTHOMAS108
Mentor
Mentor

The 'Intersect' method is a LINQ extension because CurveLoop implements IEnumerable

 

So not the 'Intersect' method you thought it was. The 'Intersect' method you are using above takes another IEnumerable of same type as an argument to list items that occur in both lists according to a comparison operator.

 

This is why it is looking for IEnumerable(of Curve) not Line.

 

You need to call Curve.Intersect on each Line and compile the results i.e. no need to use CurveLoop.

 

0 Likes
Message 3 of 7

stefano.cartaKGT96
Advocate
Advocate

Thanks for your reply..

 

I have a 3d curve created from 3d points, then I create a second curve like the first but with Z=0

I create a vertical line in a specific point of the second curve and I have to find the intersection point of the line with the first curve.

0 Likes
Message 4 of 7

RPTHOMAS108
Mentor
Mentor
Accepted solution

If I understand correctly you have a line in the 0,0,1 direction to find the same point on the 3D curve as is on the 2D?

 

Since these are all line segments could it not be solved by using similar triangles for Z?

Z1/L1 = Z2/L2

where

Z2 is the overall change in Z for the line segment (difference in Z between two ends could be +ve or -ve)

L2 is the 2D length of the line segment

Z1 is the unknown Z value at a point along the 2D length

L1 is the 2D length associated with Z1

 

L2 = Length 2d = ((End0.X - End1.X)^2 + (End0.Y.End1.Y)^2)^0.5

 

Z1 = L1 * (Z2/L2)

The final Z would be the Z at the end used for start of the measurement + Z1

 

Then X and Y are the same. 

 

 

0 Likes
Message 5 of 7

stefano.cartaKGT96
Advocate
Advocate

Thanks...

thanks for your solution...
I have another question..
Is there a way to read the curveloop coordinates at a specific lenght from the first point of the curve?

0 Likes
Message 6 of 7

RPTHOMAS108
Mentor
Mentor

CurveLoop is just a collection of joined curves it has no direct way of evaluating a point along it's length but you can probably write a function. You have to ensure that the curves are continuously joined and are joined end to start but you can reverse curves to correct those that don't.

 

If you then iterate the curves in the loop adding the length to a sum value then you get to an iteration where the sum value is greater than or equal to your target length at which you want to find the point. If you deduct the previous lengths from your target length then you get the remainder to evaluate along the current iterated curve. 

 

If a CurveLoop has more than one curve then such curves would be bound and all would have a length value. If you divide 1 by the length and multiply it by the remainder then you have a normalised value to input into Curve.Evaluate for the current iterated curve.

 

Refer to RevitAPI.chm CurveLoop class for definitions regarding what is considered continuous.

Note also that for some complex curves (splines etc.) the parameter value changes are not uniform along the curve length. 

0 Likes
Message 7 of 7

stefano.cartaKGT96
Advocate
Advocate

Thanks..

it's the same procedure I had in mind ...

I convert in code...

Stefano

0 Likes