We help IT Professionals succeed at work.

# How can I get a Beizer or NURBS from curve points?

on
Good every one!
Where are the processes about beizer line and NURBS
and it should include get Beizer or NURBS form curve points, it is better if including edit functions.
thanks!

Comment
Watch Question

## View Solution Only

Commented:
NURBS are beyond me, but bezier curves can be drawn using the PolyBezier windows GDI call. There's a nice little sample here

http://www.vbapi.com/ref/p/polybezier.html

CERTIFIED EXPERT
Commented:
Hi
Here is my spline routines:

Option Base 1
Dim M() As Single, X() As Single, Y() As Single
Dim TempArr() As Single, bNew As Boolean

'=======Get cubic spline coefficients================
'inpArr - 2D array (x,y coordinates of points)
'Return True if success, False otherwise
'====================================================
Private Function PrepareSpline(inpArr() As Single) As Boolean
Dim n As Integer, i As Integer
Dim L() As Single, R() As Single, S() As Single
Dim D As Single, E As Single, F As Single, H As Single, P As Single
PrepareSpline = False
On Error Resume Next
n = UBound(inpArr, 2)
On Error GoTo 0
If n < 2 Then Exit Function
ReDim M(n), X(n), Y(n), L(n), R(n), S(n)
For i = 1 To n
X(i) = inpArr(1, i)
Y(i) = inpArr(2, i)
Next i
D = X(2) - X(1):  E = (Y(2) - Y(1)) / D
For i = 2 To n - 1
H = D: D = X(i + 1) - X(i)
If D = 0 Then D = 0.0001
F = E: E = (Y(i + 1) - Y(i)) / D
L(i) = D / (D + H)
R(i) = 1 - L(i)
S(i) = 6 * (E - F) / (D + H)
Next i
For i = 2 To n - 1
P = 1 / (R(i) * L(i - 1) + 2)
L(i) = -L(i) * P
S(i) = (S(i) - R(i) * S(i - 1)) * P
Next i
M(n) = 0: L(n - 1) = S(n - 1): M(n - 1) = L(n - 1)
For i = n - 2 To 1 Step -1
L(i) = L(i) * L(i + 1) + S(i)
M(i) = L(i)
Next i
PrepareSpline = True
End Function

'===================================================
'Use above coefficients to calculate value with inter/extrapolation
'====================================================
Private Function CalcValue(arg As Single) As Single
Dim ret As Single, i As Integer, n As Integer
Dim D As Single, H As Single, P As Single, R As Single
n = UBound(X)
For i = 1 To n
If arg < X(i) Then Exit For
Next i
Select Case i
Case 1    ' arg less then x(1) -> Extrapolation
D = X(2) - X(1)
If D = 0 Then D = 0.0001
ret = -D * M(2) / 6 + (Y(2) - Y(1)) / D
ret = ret * (arg - X(1)) + Y(1)
Case n + 1 ' arg greater then x(n) -> Extrapolation
D = X(n) - X(n - 1)
If D = 0 Then D = 0.0001
ret = D * M(n - 1) / 6 + (Y(n) - Y(n - 1)) / D
ret = ret * (arg - X(n)) + Y(n)
Case Else  'interpolation
D = X(i) - X(i - 1): H = arg - X(i - 1)
R = X(i) - arg: P = D * D / 6
ret = (M(i - 1) * R ^ 3 + M(i) * H ^ 3) / (6 * D)
ret = ret + ((Y(i - 1) - M(i - 1) * P) * R + (Y(i) - M(i) * P) * H) / D
End Select
CalcValue = ret
End Function

Private Sub Command1_Click()
If PrepareSpline(TempArr) Then
DrawCurve Val(Text2)
Else
MsgBox "Unable to draw curve", vbOKOnly + vbCritical
End If
End Sub

Private Sub Command2_Click()
Picture1.Cls
Text1 = "  X" & vbTab & "  Y" & vbCrLf & "---------------------------"
Text2 = "1"
ReDim TempArr(2, 1)
bNew = True
End Sub

Text1 = "  X" & vbTab & "  Y" & vbCrLf & "---------------------------"
Text2 = "1"
Caption = "Cubic Spline Interpolation"
Label1 = "Prepare points array by clicking on PictureBox. When finished, press DrawCurve button to continue."
Label1 = Label1 & vbCrLf & "In the TextBox below you can see your array."
Label1 = Label1 & vbCrLf & " Default step of curve is 1 pixel. If you want to change it, type new value at TextBox near Command Button."
Picture1.FillColor = vbRed
Picture1.FillStyle = vbSolid
Command1.Caption = "&DrawCurve"
Command2.Caption = "&Clear"
bNew = True
End Sub

Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim i As Integer
Static n1 As Integer
If bNew Then
n1 = 0
bNew = False
End If
If Button = 1 Then
n1 = n1 + 1
ReDim Preserve TempArr(2, n1)
TempArr(1, n1) = X
TempArr(2, n1) = Y
Text1 = Text1 & vbCrLf & TempArr(1, n1) & vbTab & TempArr(2, n1)
Picture1.Circle (X, Y), 50
End If
End Sub

Private Sub DrawCurve(iStep As Integer)
Dim i As Integer
Picture1.PSet (X(LBound(X)), CalcValue(X(LBound(X))))
For i = X(LBound(X)) + iStep To X(UBound(X)) Step iStep
Picture1.Line -(i, CalcValue(CSng(i)))
Next i
End Sub

'To try this sample, place picturebox, two textboxes (1 - multiline),label and command button on form.

Cheers

Commented:
very interesting ark :)

Commented:
ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.  Moderators Computer101 or Netminder will return to finalize these if still open in seven days.  Please post closing recommendations before that time.

Question(s) below appears to have been abandoned. Your options are:

1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the participants why you wish to do this, and allow for Expert response.  This choice will include a refund to you, and will move this question to our PAQ (Previously Asked Question) database.  If you found information outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
--> Post comments for expert of your intention to delete and why
--> YOU CANNOT DELETE A QUESTION with comments; special handling by a Moderator is required.

For special handling needs, please post a zero point question in the link below and include the URL (question QID/link) that it regards with details.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt

Click you Member Profile to view your question history and keep them updated as the collaboration effort continues, to maintain your open and locked questions.  If you are a  KnowledgePro user, use the Power Search option to find them.  Anytime you have questions which are LOCKED with a Proposed Answer which does not serve your needs, please reject it and add comments as to why.  In addition, when you do grade the question, if the grade is less than an A, please add a comment as to why.  This helps all involved, as well as future persons who may access this item for help.

http://www.experts-exchange.com/questions/Q.20187570.html
http://www.experts-exchange.com/questions/Q.20245580.html
http://www.experts-exchange.com/questions/Q.20262730.html

http://www.experts-exchange.com/questions/Q.20179192.html

**** PLEASE DO NOT AWARD THE POINTS TO ME. *****

------------>  EXPERTS:  Please leave your closing recommendations if this item remains inactive another seven (7) days.  If you are interested in the cleanup effort, please click this link http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643
POINTS FOR EXPERTS awaiting comments are listed here -> http://www.experts-exchange.com/commspt/Q.20277028.html

Moderators will finalize this question if still open in @7 days, by either moving this to the PAQ (Previously Asked Questions) at zero points, deleting it or awarding expert(s) when recommendations are made, or an independent determination can be made.  Expert input is always appreciated to determine the fair outcome.

Thank you everyone.

Moondancer
Moderator @ Experts Exchange

Commented:
Finalized, no response.
Moondancer - EE Moderator