Showing results for 
Search instead for 
Did you mean: 

About GetRayIntersections API

Valued Contributor
Valued Contributor

Hi, all,

I am working with SE ST6 now. GetRayIntersections API is added since ST5 MP1 for intersections calculation. However, there is no further information about this API in SDK reference. 


Here is the declaration:


Public Sub GetRayIntersections( _
   ByRef Bodies() As Object, _
   ByRef Origins() As Double, _
   ByRef Directions() As Double, _
   ByVal NumRays As Long, _
   ByVal Radius As Double, _
   ByVal Offset As Double, _
   ByRef NumIntersections As Long, _
   ByRef BodyIndex() As Long, _
   ByRef IntersectionPoints() As Double, _
   ByRef IntersectionNormals() As Double, _
   ByRef RayIndex() As Long, _
   ByRef Entity() As RayIntersectionEntityConstants, _
   Optional ByRef Type As Variant _

Is there anyone who knows the meaning of Radius and Offset parameters? I have tested for several days with it and still cannot figure out how to choose the value for parameters, especially for Radius. My GUESS is that Radius stands for the radius of the Ray.



My test case is simple. I have two parts. One (TestCase I) is a ball with radius 50mm at (0, 0, 0), the other (TestCase II) is a box 30mm x 40mm x 50 mm at (0, 0, 0). And Here is my code, which is simple, although I have struggled for a day to get rid of the invalid argument exception.Man Frustrated



Dim objBodies(0 To 1) As Object 
'HERE!! I don't know why I have to allocate more than one elements to make things work
objBodies(0) = objDoc.Models.Item(1).Body

Dim Origins(2) As Double
Origins(0) = -1.0
Origins(1) = 0.0
Origins(2) = 0.0

Dim Directions(2) As Double
Directions(0) = 1.0
Directions(1) = 0.0
Directions(2) = 0.0

Dim NumIntersections As Integer
Dim BodyIndex(0) As Integer
Dim IntersectionPoints(0) As Double
Dim IntersectionNormals(0) As Double
Dim RayIndex(0) As Integer

Dim Entity(0) As SolidEdgePart.RayIntersectionEntityConstants
Dim Type(0) As SolidEdgeConstants.RayIntersectionTypeConstants

objDoc.GetRayIntersections(objBodies, Origins, Directions, 1, RADIUS, 0.0,
       NumIntersections, BodyIndex, IntersectionPoints,
       IntersectionNormals, RayIndex, Entity, Type)



The value of Offset is set to 0.0, because I don't know how it will affect the result after being tesed for a while.


If Radius is set to 0.0, TestCase I failed (NumIntersections = 0, it should be 2) when


Origins(0) = -1.0
Origins(1) = 0.0
Origins(2) = 0.01

while keep other parameters unchanged. On the contrary, TestCase II is OK.


To me, this result means VERY small Radius is not enough to calculate all intersection points for a certain model. Then, I tested for several Radius values and found that this particular value 0.0000000297329865 seems to give me the correct result on TestCase I. But what does it mean? Is it unique for all possible models? Does it work for all Originals and Directions? How to derive it?


I would appreciate it if someone could give me some suggestions. Sorry for my English.







Re: About GetRayIntersections API

Solution Partner Phenom Solution Partner Phenom
Solution Partner Phenom

I was also playing a little bit with your code and my own testcase.

As you, I couldn't determine the meaning of the "offset" parameter either.

The radius parameter defines the radius of ray and is taken into consideration, if the center of the ray hits a face. If there is also an edge or vertex inside the radius of the ray, the additional edge/vertex is also returned. If the ray center hits an edge, the face is NOT returned.

If you are going to test multiple rays, then you have to define 3 doubles with the x-, y-, and z-value for each ray in the origin and direction arrays.

Below is my updated test code and its output. You should simply run the code on an empty Part document.

    ' PAR: Compute BODY <-> RAY intersections
    Dim objDoc As PartDocument = objApp.ActiveDocument
    objDoc.ModelingMode = ModelingModeConstants.seModelingModeOrdered

    ' Create a cylinder (Body#0) with 50 mm radius at the origin
    Dim objProfileSet As ProfileSet = objDoc.ProfileSets.Add()
    Dim objProfile As Profile = objProfileSet.Profiles.Add(objDoc.RefPlanes.Item(1))
    objProfile.Circles2d.AddByCenterRadius(0, 0, 0.05)
    objProfile.Visible = False
    objDoc.Models.AddFiniteExtrudedProtrusion(1, {objProfile}, igBoth, 0.1)

' Create a second cylinder (Body#1) at distance=150mm from origin objDoc.Models.AddBody(AddBodyTypeConstants.igPartType, "Design Body 2") objProfileSet = objDoc.ProfileSets.Add() objProfile = objProfileSet.Profiles.Add(objDoc.RefPlanes.Item(1)) objProfile.Circles2d.AddByCenterRadius(0.15, 0, 0.05) objProfile.End(ProfileValidationType.igProfileClosed) objProfile.Visible = False objDoc.Models.AddFiniteExtrudedProtrusion(1, {objProfile}, igBoth, 0.1) ' Find the ray <-> body intersections
' Collect all design bodies in this part document Dim bodies As New List(Of Object) For Each objMdl As Model In objDoc.Models bodies.Add(objMdl.Body) Next bodies.Add(Nothing)
' Define Ray#0 and Ray#1 Dim origin() As Double = {-1, 0.0, 0.001, _ -1, 0.0, 0.01} Dim direction() As Double = {1, 0, 0, _ 1, 0, 0} Dim numIntersections As Integer Dim bodyIndex As Array = Array.CreateInstance(GetType(Integer), 0) Dim pnt As Array = Array.CreateInstance(GetType(Double), 0) Dim nrm As Array = Array.CreateInstance(GetType(Double), 0) Dim rayIndex As Array = Array.CreateInstance(GetType(Integer), 0) Dim entity As Array = Array.CreateInstance(GetType(SolidEdgePart.RayIntersectionEntityConstants), 0)
' Do the intersection objDoc.GetRayIntersections(bodies.ToArray(), origin, direction, 2, 0.001, 0.0, numIntersections, bodyIndex, pnt, nrm, rayIndex, entity) For i As Integer = 0 To numIntersections - 1 Dim strPos As String = String.Format("P({0:F1},{1:F1},{2:F1})", pnt(i * 3) * 1000.0, pnt(i * 3 + 1) * 1000.0, pnt(i * 3 + 2) * 1000.0) Dim strNrm As String = String.Format("N({0:F3},{1:F3},{2:F3})", nrm(i * 3), nrm(i * 3 + 1), nrm(i * 3 + 2)) Dim strType As String = IIf(entity(i) = RayIntersectionEntityConstants.seFace, "FACE", _ IIf(entity(i) = RayIntersectionEntityConstants.seEdge, "EDGE", _ IIf(entity(i) = RayIntersectionEntityConstants.seVertex, "VERTEX", _ "<unknown>"))) Debug.Print(i & ") Ray#" & rayIndex(i) & " -> Body#" & bodyIndex(i) & ": " & strPos & " " & strNrm & " Type:" & strType) Next

The debug output of the code above:


0) Ray#0 -> Body#0:  P(-50.0,0.0,1.0)  N(-1.000,0.000,0.000)  Type:FACE
1) Ray#0 -> Body#0:  P(-50.0,0.0,1.0)  N(0.000,0.000,0.000)  Type:EDGE
2) Ray#0 -> Body#0:  P(50.0,0.0,1.0)  N(1.000,0.000,0.000)  Type:FACE
3) Ray#0 -> Body#1:  P(100.0,0.0,1.0)  N(-1.000,0.000,0.000)  Type:FACE
4) Ray#0 -> Body#1:  P(100.0,0.0,1.0)  N(0.000,0.000,0.000)  Type:EDGE
5) Ray#0 -> Body#1:  P(200.0,0.0,1.0)  N(1.000,0.000,0.000)  Type:FACE
6) Ray#1 -> Body#0:  P(-50.0,0.0,10.0)  N(-1.000,0.000,0.000)  Type:FACE
7) Ray#1 -> Body#0:  P(50.0,0.0,10.0)  N(1.000,0.000,0.000)  Type:FACE
8) Ray#1 -> Body#1:  P(100.0,0.0,10.0)  N(-1.000,0.000,0.000)  Type:FACE
9) Ray#1 -> Body#1:  P(200.0,0.0,10.0)  N(1.000,0.000,0.000)  Type:FACE