Quantcast
Channel: MicroStation Programming Forum - Recent Threads
Viewing all articles
Browse latest Browse all 4331

[V8i VBA] IntersectRay3d Method - Reasons for failure?

$
0
0

I saw the other recent topic (Cone intersection with a rectangle) and it reminded me I was going to test out some methods, one of those being IntersectRay3d. Using that thread's problem as a test case, I created a simple mock-up, manually creating a cone and a rectangle, positioned them so they intersected and wrote my code. I was only concerned with the cone  centre (from base to top) and programmatically created a Ray3D and a BsplineSurface to detect the intersection. Everything worked fine when the cone and rectangle had their centre's aligned in plan, however when moving the cone to align with one of the rectangle's short edges, the intersection was not detected. This wasn't unexpected, though I presume the Ray3D has no concept of 'thickness' or 'radius', but I decided to move the cone back towards the centre by 1mm, I felt this was a significant enough value for the intersection to be detected. How wrong I was! Again, no intersection detected. This was unexpected so I repeated the shift but using increments of 10mm/5mm/1mm until I reached the point where the intersection was detected. For whatever reason that I cannot fathom, 150mm appears be the accepted threshold!!

See for yourself:

Code:

Public Sub Main()
    Dim oBsplineSurface                          As New BsplineSurface
    Dim oCone                                    As ConeElement
    Dim oRectangle                               As ShapeElement
    Dim pConeBaseCenterPoint                     As Point3d
    Dim pConeTopCenterPoint                      As Point3d
    Dim pIntersectionPoint                       As Point3d
    Dim pParams                                  As Point2d
    Dim Ray                                      As Ray3d'GetElementID used purely for convenience when testing - change values to suit your own test case file.
    Set oCone = ActiveModelReference.GetElementByID(DLongFromString("742"))
    Set oRectangle = ActiveModelReference.GetElementByID(DLongFromString("743"))

    pConeBaseCenterPoint = oCone.BaseCenterPoint
    pConeTopCenterPoint = oCone.TopCenterPoint
    
    Ray.Origin = pConeBaseCenterPoint
    Ray.Direction = pConeTopCenterPoint
    
    'Uncomment below to create graphical representation of Ray3D used for intersection calculation'    Dim RayLine                                  As LineElement'    Set RayLine = CreateLineElement2(Nothing, pConeBaseCenterPoint, pConeTopCenterPoint)'    RayLine.Color = 4'    RayLine.LineStyle = ActiveDesignFile.LineStyles("3")'    ActiveModelReference.AddElement RayLine
    oBsplineSurface.FromElement oRectangle'Uncomment below to create graphical representation of BsplineSurface used for intersection calculation'    Dim oBsplineSurfaceElement                   As BsplineSurfaceElement'    Set oBsplineSurfaceElement = CreateBsplineSurfaceElement1(Nothing, oBsplineSurface)'    oBsplineSurfaceElement.Color = 5'    ActiveModelReference.AddElement oBsplineSurfaceElement'    oBsplineSurfaceElement.Redraw

    If oBsplineSurface.IntersectRay3d(pIntersectionPoint, pParams, Ray) = True Then
        MsgBox ("Intersection found!")
    Else
        MsgBox ("No intersection found")
    End If
End Sub

Is there any reason for this behaviour or have I stumbled onto something unexpected?


Viewing all articles
Browse latest Browse all 4331

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>