2 Replies Latest reply on Apr 25, 2016 5:41 AM by Alexandre Gragnano

    Torus face analyse

    Alexandre Gragnano

      I have a piece of torus face (from a more complex body) to analyse like this:

      TorusCutaway.png

       

      I would like to calculate the neutral axis length with:

      • The surface TorusParams (TorusParams Property (ISurface)) which give me:
        • a center point (x, y, z)
        • an axis vector (x, y, z)
        • a major radius (R on image)
        • a minor radius (r on image)
      • The extremity curves (CircleParams Property (ICurve)) which give me:
        • the extremity points of neutral axis (x, y, z)
        • other informations...

       

      To calculate this length:

      • I calculate an angle (rad) but the angle can be:
        • small: angle
        • large: 2*PI - angle
      • To determine the angle to use, I calculate:
        • the [center, extremity1] vector (x, y, z)
        • the [center, extremity2] vector (x, y, z)
        • the cross product of the vectors (x, y, z)
        • the dot product with the torus axis vector
          • if the dot product is positive (same direction):
            • the torus turns in a clockwise direction
          • if the dot product is negative (opposite direction)
            • the torus turns in an anti-clockwise direction

       

      My problem is:

      • The torus axis is based on a starting and ending point (extremity1 or extremity2) but I don't know which one.

       

      How can I find it?

       

      Thank you for your help.

        • Re: Torus face analyse
          Simon Turner

          How about you pick one point on the surface and check which segment it lies on.

          For example, find the minimum and maximum U and V values for the surface and create a point at ((minU + maxU) / 2, (minV + maxV) / 2)

          You can create a vector from the center point, towards the new point (call it point1), but in the plane of the neutral axis in a few different ways. One way is like this:

          v1 = [center, point1]

          v2 = v1 * axis (cross product)

          v3 = v2 * axis - this should hopefully be a vector from the center, towards point1, but in the plane of the neutral axis

          v3.Length = radius of neutral axis. Now the end point of v3 should be a point on the neutral axis, in between the extremities.

            • Re: Torus face analyse
              Alexandre Gragnano

              It took me time to understand your response .

              (I am not familiar with u & v parameters).

              Thank you very much for your help.

               

              I share some VBA test results for those that it might help:

              Option Explicit
              
              Dim app As SldWorks.SldWorks
              Dim doc As SldWorks.ModelDoc2
              Dim selMgr As SldWorks.SelectionMgr
              Dim skMgr As SldWorks.SketchManager
              Dim segment As SldWorks.SketchSegment
              
              Dim face As SldWorks.Face2
              Dim uvBounds As Variant
              Dim uMin As Double
              Dim uMax As Double
              Dim uMid As Double
              
              Dim surface As SldWorks.surface
              Dim torusData As Variant
              Dim centerX As Double
              Dim centerY As Double
              Dim centerZ As Double
              Dim majorRadius As Double
              Dim minorRadius As Double
              Dim outerRadius As Double
              
              Dim angle As Double
              Dim radius As Double
              Dim diameter As Double
              Dim length As Double
              
              Dim startData As Variant
              Dim startX As Double
              Dim startY As Double
              Dim startZ As Double
              
              Dim middleData As Variant
              Dim middleX As Double
              Dim middleY As Double
              Dim middleZ As Double
              
              Dim endData As Variant
              Dim endX As Double
              Dim endY As Double
              Dim endZ As Double
              
              Sub main()
                  
                  Set app = Application.SldWorks
                  Set doc = app.ActiveDoc
                  Set selMgr = doc.SelectionManager
                  Set skMgr = doc.SketchManager
                  
                  Set face = selMgr.GetSelectedObject6(1, 0)
                  uvBounds = face.GetUVBounds()
                  uMin = uvBounds(0)
                  uMax = uvBounds(1)
                  uMid = (uMin + uMax) / 2
                  
                  Set surface = face.GetSurface()
                  torusData = surface.TorusParams
                  centerX = torusData(0)
                  centerY = torusData(1)
                  centerZ = torusData(2)
                  majorRadius = torusData(6)
                  minorRadius = torusData(7)
                  outerRadius = majorRadius + minorRadius
                  
                  angle = uMax - uMin
                  radius = majorRadius
                  diameter = minorRadius * 2
                  length = majorRadius * angle
                  
                  Debug.Print ("Angle (deg): " & angle * 45 / Atn(1))
                  Debug.Print ("Radius (mm): " & radius * 1000)
                  Debug.Print ("Diameter (mm): " & diameter * 1000)
                  Debug.Print ("Length (mm): " & length * 1000)
                  
                  startData = surface.evaluate(uMin, 0, 0, 0)
                  startX = centerX + majorRadius * (startData(0) - centerX) / outerRadius
                  startY = centerY + majorRadius * (startData(1) - centerY) / outerRadius
                  startZ = centerZ + majorRadius * (startData(2) - centerZ) / outerRadius
                  
                  middleData = surface.evaluate(uMid, 0, 0, 0)
                  middleX = centerX + majorRadius * (middleData(0) - centerX) / outerRadius
                  middleY = centerY + majorRadius * (middleData(1) - centerY) / outerRadius
                  middleZ = centerZ + majorRadius * (middleData(2) - centerZ) / outerRadius
                  
                  endData = surface.evaluate(uMax, 0, 0, 0)
                  endX = centerX + majorRadius * (endData(0) - centerX) / outerRadius
                  endY = centerY + majorRadius * (endData(1) - centerY) / outerRadius
                  endZ = centerZ + majorRadius * (endData(2) - centerZ) / outerRadius
                  
                  skMgr.Insert3DSketch (True)
                  Set segment = skMgr.CreateLine(centerX, centerY, centerZ, startX, startY, startZ)
                  Set segment = skMgr.CreateLine(centerX, centerY, centerZ, middleX, middleY, middleZ)
                  Set segment = skMgr.CreateLine(centerX, centerY, centerZ, endX, endY, endZ)
                  
              End Sub
              

               

              -180° Result:

              Capture29.JPG

              Debug:

              Angle (deg): 150

              Radius (mm): 100

              Diameter (mm): 29,5

              Length (mm): 261,79938779915

               

              +180° Result:

              Capture30.JPG

               

              Debug:

              Angle (deg): 275

              Radius (mm): 100

              Diameter (mm): 29,5

              Length (mm): 479,965544298443