TBC Macros and Extensions

 View Only
Expand all | Collapse all

Measuring the angle between two Trimble.Vce.Alignment.Linestring.Linestring type features

  • 1.  Measuring the angle between two Trimble.Vce.Alignment.Linestring.Linestring type features

    Posted 02-26-2023 11:08

    Hello Trimble SDK community,

    I'm wondering what is the easiest method to measure the angle between two  Trimble.Vce.Alignment.Linestring.Linestring instances?

    Thanks,



    ------------------------------
    Morteza Kiani
    ------------------------------


  • 2.  RE: Measuring the angle between two Trimble.Vce.Alignment.Linestring.Linestring type features

    Posted 02-26-2023 15:14

    Most likely something like this, not tested though.  I assume you don't just have simple 2 node lines. Then you could just retrieve the start and end node of each line, create 2 Vector3D and of you go.

    In case of general linestrings, which may contain arcs/curves, you need to convert them to polysegs and intersect those. Compute the station on each polyseg and then use .FindPointFromStation since only that one delivers us the correct segment orientation at the specified station location in form of the perpendicular vector .

            from Trimble.Vce.Geometry import Intersections
    
                polyseg1 = l1.ComputePolySeg()
                polyseg1 = polyseg1.ToWorld()
                polyseg2 = l2.ComputePolySeg()
                polyseg2 = polyseg2.ToWorld()
    
                intersections = Intersections()
                if polyseg1.Intersect(polyseg2, True, intersections): # True stands for ignore Z when testing
                    for i in intersections:
                        outPointOnCL = clr.StrongBox[Point3D]()
                        station = clr.StrongBox[float]()
    
                        polyseg1.FindPointFromPoint(i.Point, outPointOnCL, station)
                        sta1 = station.Value
                        polyseg2.FindPointFromPoint(i.Point, outPointOnCL, station)
                        sta2 = station.Value
    
                        outSegment1 = clr.StrongBox[Segment]()
                        outSegment2 = clr.StrongBox[Segment]()
                        out_t1 = clr.StrongBox[float]()
                        out_t2 = clr.StrongBox[float]()
                        outPointOnCL1 = clr.StrongBox[Point3D]()
                        outPointOnCL2 = clr.StrongBox[Point3D]()
                        perpVector3D1 = clr.StrongBox[Vector3D]() # Vector containing the normalized line parameters for a line perpendicular 
                        perpVector3D2 = clr.StrongBox[Vector3D]() # and to the right of the PointOnCL on the polyseg
                        outdeflectionAngle1 = clr.StrongBox[float]()
                        outdeflectionAngle2 = clr.StrongBox[float]()
    
                        polyseg1.FindPointFromStation(sta1, outSegment1, out_t1, outPointOnCL1, perpVector3D1, outdeflectionAngle1) # compute point and vector on line 1
                        polyseg2.FindPointFromStation(sta2, outSegment2, out_t2, outPointOnCL2, perpVector3D2, outdeflectionAngle2) # compute point and vector on line 2
    
                        angle = perpVector3D1.Value.Azimuth - perpVector3D1.Value.Azimuth
    
                    intersections.Clear() # in case you run this in a loop the intersections must be cleared



    ------------------------------
    Ronny Schneider
    ------------------------------



  • 3.  RE: Measuring the angle between two Trimble.Vce.Alignment.Linestring.Linestring type features

    Posted 02-26-2023 17:43

    Thanks Ronny!

    I believe I learned how to work with vectors (2D and 3D) from one of your old posts that was a response to another user and based on your previous script, I thought about it using vectors too but hearing this it from you now, I'm frim that the vectors will be the most convenient way of doing this.

    Thanks a bunch,



    ------------------------------
    Morteza Kiani
    ------------------------------