Description This function adds a new spline curve to the document and returns the node number of the newly added entity.
Syntax n = AddSplineCurve(entity, degree, breakpoints(), coefs() )
Parameters n (Long) Returned node number of the curve that was added to the document.
entity As T_ENTITY This structure variable contains the generic information about the curve (parent on the tree, traceability, name, etc.). This structure may be initialized using InitEntity or by manually setting the members of the T_ENTITY structure.
degree As Long This argument sets the degree for each parametric segment in the spline curve. Each segment in the spline will then contain degree+1 coefficients in X, Y and Z.
breakpoints() As Double This array argument contains the breakpoints for the spline curve. The breakpoint values must be increasing and will define the range of the parametric variable for each segment. For example, if breakpoints() has an upper bound of 2, with the values [0, 2, 3], this means that there will be two segments in the spline curve. The first segment has length 2, with the parametric variable ranging from 0 to 2, and the second segment has length 1 with the parametric variable ranging from 0 to 1.
coefs() As Double This argument is a 3xN array that contains the coefficients of all segments in the spline. The first dimension corresponds to the segment columns as seen in the GUI, which contain the coefficients for the polynomials in X, Y and Z, respectively. The second dimension corresponds to the segment rows as seen in the GUI, where N is (degree+1)*(Nbreakpoints-1). For example, if breakpoints() has the values [0,2,3], then Nbreakpoints = 3 and there are 2 segments. If degree is 1 (i.e. segments are linear), then the second dimension of coefs() has size (2)*(2) = 4. The first two index values, 0 and 1, correspond to the coefficients of the first segment and the second two index values, 2 and 3, correspond to the coefficients of the second segment.
Example The example below demonstrates a script that uses the spline curve construct to build a linear approximation to a circular arc using N segments.
Sub Main
'Construction parameters of the arc Dim R As Double, T As Double, nSeg As Long R = 10 'radius T = 45 'subtended angle from the COC nSeg = 5 'number of linear segments
'Derived angular step for each segment Dim dT As Double dT = T / nSeg
'Calculate values needed to define the linear spline segments 'Y and Z points define the endpoints of each segment 'lens is the length of each segment 'Y and Z slopes are calculated so that each linear segment passes through the end points Dim curSeg As Long Dim yPts() As Double, zPts() As Double Dim ySlopes() As Double, zSlopes() As Double, lens() As Double ReDim yPts(nSeg) : ReDim zPts(nSeg) ReDim ySlopes(nSeg-1) : ReDim zSlopes(nSeg-1) : ReDim lens(nSeg-1) yPts(0) = 0 : zPts(0) = 0 For curSeg = 1 To nSeg yPts(curSeg) = R * Sin( DegToRad( curSeg * dT ) ) zPts(curSeg) = R * (1 - Cos( DegToRad( curSeg * dT ) )) lens(curSeg-1) = Sqr( (yPts(curSeg)-yPts(curSeg-1))^2 + (zPts(curSeg)-zPts(curSeg-1))^2 ) ySlopes(curSeg-1) = (yPts(curSeg)-yPts(curSeg-1))/lens(curSeg-1) zSlopes(curSeg-1) = (zPts(curSeg)-zPts(curSeg-1))/lens(curSeg-1) Next
'Construct the curve using linear segments Dim nCurve As Long, tEnt As T_ENTITY, nDeg As Long Dim bps() As Double, coeffs() As Double ReDim bps(nSeg) : ReDim coeffs(2,2*nSeg-1) InitEntity(tEnt) tEnt.parent = FindFullName( "Geometry.Elem 1" ) tEnt.name = "Linear Spline" tEnt.traceable = True nDeg = 1 'linear segments
'Populate the breakpoint list. Breakpoints need to be in 'increasing order. The difference between adjacent breakpoints 'defines the length of the parametric value for a given segment. bps(0) = 0 For curSeg = 1 To nSeg bps(curSeg) = lens(curSeg-1) + bps(curSeg-1) Next
'The coefficients array is a 2xN array, where the first index 'specifies the X,Y and Z coefficients (column values in the GUI). 'The second index has size nSeg*(nDeg+1)-1. For example, if there are 'three linear segments, nDeg=1 and the coefficients array will have 'dimensions 2x7, since each of the three segments have 2 coefficients in 'X,Y and Z and the indexing starts at 0 (i.e. 8 total coefficients for each 'of X,Y and Z across all segments). 'The looping structure shown here is a loop over the segments rather than 'the total number of coefficients. For curSeg = 0 To nSeg-1 coeffs(1,curSeg*2) = yPts(curSeg) coeffs(1,curSeg*2+1) = ySlopes(curSeg) coeffs(2,curSeg*2) = zPts(curSeg) coeffs(2,curSeg*2+1) = zSlopes(curSeg) Next nCurve = AddSplineCurve( tEnt, nDeg, bps(), coeffs() )
'Make the curve drawable in the 3D view Dim tC As T_CURVEBASICINFO GetCurveBasicInfo( nCurve, tC ) tC.curveDraw = True SetCurveBasicInfo( nCurve, tC )
'Update the document Update
End Sub
See Also
|