Interpolation for free form curves

Technical discussions
Post Reply
John M
Posts: 6
Joined: Fri Sep 25, 2015 6:50 am

Interpolation for free form curves

Post by John M »

I have a question about Free Form curves in KernelCAD 3.2. I need to create a 3D spline curve. I've read your documentation and written a test function based on that. I think I'm not understanding something. I think I need an object (iSection?) to be created in the model but I'm not sure how to link this to the curve. My test code (VB6) is below. Any advice you might be able to offer would be appreciated.
Regards
John

Code: Select all

Option Explicit

Dim m_iModel As iModel                           ' model object
Dim Xp(0 To 5) As Double
Dim Yp(0 To 5) As Double
Dim Zp(0 To 5) As Double

'----------------------------------------------------------------------
' Spline Test #1
'----------------------------------------------------------------------
Private Sub mnuSpline1_Click()
   Dim iGenerator As IDIObjGenerator             ' object generator
   Dim iUnknown As Variant                       '
   Dim iCurve1 As ICurve                         '
   Dim iCurveFF As ICurveFreeForm                '
   Dim iArr As IArray2                           '
   Dim iArr3D As IArray3D                        '
   Dim i As Long                                 '
   Dim iCurveSectKC As ILineSection_KC           '
   Dim iSect As ISection                         '

' 1. Load some test points

   Load_Points

' 2. Create a new freeformcurve object

   Set iGenerator = CreateObject("KERNELCAD.DIObjGenerator.1")
   Set iUnknown = iGenerator.Create(EObjectType.eObjTypeFreeFormCurve)
   Set iCurveFF = iUnknown
   Set iArr3D = iCurveFF.GetData

' 3. Load the data points

   iArr3D.SetCount 5

   For i = 0 To 4
      iArr3D.Set i, Xp(i), Yp(i), Zp(i)
   Next i

   iCurveFF.SetInterpolationDegree 2

' 4. Update the display

   KernelCAD1.UpdateSurface
End Sub

'----------------------------------------------------------------------
' Load some test data points
'----------------------------------------------------------------------
Sub Load_Points()
   Xp(0) = 0#:   Yp(0) = 0#:   Zp(0) = 0#
   Xp(1) = 10#:  Yp(1) = 10#:  Zp(1) = 3#
   Xp(2) = 20#:  Yp(2) = 15#:  Zp(2) = 7#
   Xp(3) = 30#:  Yp(3) = 7#:   Zp(3) = 7#
   Xp(4) = 20#:  Yp(4) = 3#:   Zp(4) = 3#
   Xp(5) = 1#:   Yp(5) = 1#:   Zp(5) = 0#
End Sub

'----------------------------------------------------------------------



nickz
Site Admin
Posts: 236
Joined: Fri Jul 26, 2013 3:58 am

Re: Interpolation for free form curves

Post by nickz »

Hi John
I believe this is used to define pipes only currently (Pipes sample)
You are right. To add the curve to the model you need to wrap it into a Section. Not all pure geometric objects have it, but curves do. There is a LineSection, represented by ILineSection_KC (EObjectType.eObjTypeLineSection) for that. See the modified version of your code below. See the 4 and 5 steps there. I did not try to run it.

Code: Select all

Option Explicit

Dim m_iModel As iModel                           ' model object
Dim Xp(0 To 5) As Double
Dim Yp(0 To 5) As Double
Dim Zp(0 To 5) As Double

'----------------------------------------------------------------------
' Spline Test #1
'----------------------------------------------------------------------
Private Sub mnuSpline1_Click()
   Dim iGenerator As IDIObjGenerator             ' object generator
   Dim iUnknown As Variant                       '
   Dim iCurve1 As ICurve                         '
   Dim iCurveFF As ICurveFreeForm                '
   Dim iArr As IArray2                           '
   Dim iArr3D As IArray3D                        '
   Dim i As Long                                 '
   Dim iCurveSectKC As ILineSection_KC           '
   Dim iSect As ISection

' 1. Load some test points

   Load_Points

' 2. Create a new freeformcurve object

   Set iGenerator = CreateObject("KERNELCAD.DIObjGenerator.1")
   Set iUnknown = iGenerator.Create(EObjectType.eObjTypeFreeFormCurve)
   Set iCurveFF = iUnknown
   Set iArr3D = iCurveFF.GetData

' 3. Load the data points

   iArr3D.SetCount 5

   For i = 0 To 4
      iArr3D.Set i, Xp(i), Yp(i), Zp(i)
   Next i

   iCurveFF.SetInterpolationDegree 2

' 4. Wrap the curve into a section to add to the model

   Set iUnknLineSection = iGenerator.Create(EObjectType.eObjTypeLineSection)
   Dim iLinesect As ILineSection_KC  
   Set iLinesect = iUnknLineSection
   iLinesect.SetCurve iCurveFF

' 5. Add the section to the model
   Dim iSectLine As ISection
   Set iSectLine = iLinesect  ' Or iUnknLineSection
   Dim iMod As IModel
   Set iMod = kernelCAD.GetModel()
   Dim iMod2 As IModel2
   Set iMod2 = iMod
   iMod2.Add iSectLine

' 6. Update the display

   KernelCAD1.UpdateSurface
End Sub

'----------------------------------------------------------------------
' Load some test data points
'----------------------------------------------------------------------
Sub Load_Points()
   Xp(0) = 0#:   Yp(0) = 0#:   Zp(0) = 0#
   Xp(1) = 10#:  Yp(1) = 10#:  Zp(1) = 3#
   Xp(2) = 20#:  Yp(2) = 15#:  Zp(2) = 7#
   Xp(3) = 30#:  Yp(3) = 7#:   Zp(3) = 7#
   Xp(4) = 20#:  Yp(4) = 3#:   Zp(4) = 3#
   Xp(5) = 1#:   Yp(5) = 1#:   Zp(5) = 0#
End Sub

'----------------------------------------------------------------------



Post Reply