Home > Software engineering >  Great god help me to modify the program genuflect is begged! ~ thank humbly
Great god help me to modify the program genuflect is begged! ~ thank humbly

Time:10-08

1, I now need to extract the b-spline curve program, remove the Bezier curve curve program command,
2, or directly to write a small program, extraction of 400 data points, then smooth connection, data points are on the smooth curve,
thank humbly!
'in this case, the black line is at various points in the coordinate system of direct connection
'yellow line only to the point of connection between an approximate fitting, not by each point, using the B spline curve, a generalized bezier
'blue line through points except the first and the last point of each point, the Bezier curve is used the Bezier

Option Explicit
Private define the data structure of the point Type Vi '
As a Double x
Y As Double
End Type

Dim Pts (64) As the Vi, Ypts (64) As a Double 'temporary point coordinates used for drawing the Bezier
Dim Points (3) As the Vi, PointsB (3) As the Vi
Dim Po (1 To 100) As the Vi

Dim CosNN (158) As Double 'used by cosine value look-up table to obtain Angle

'the Bezier computing
Private Sub calc_spline (Npts As Integer)
Dim x As Double, dx As Double, DDX As Double, DDDX As Double
Dim As Double, y dy As Double, ddy As Double, dddy As Double
Dim As Integer I
Dim As Double, dt dt2 As Double, dt3 As Double
Dim xdt2_term As Double, xdt3_term As Double
Dim ydt2_term As Double, ydt3_term As Double

Dt=1 #/(Npts)
Dt2=(dt * dt)
Dt3=dt2 * (dt)
'x coordinate increment
Xdt2_term=3 * (Points (2) x - 2 * Points (1), x + Points (0). X)
Xdt3_term=Points (3). X + 3 * (- Points (2) x + Points (1), x) - Points (0) x

Xdt2_term=dt2 * xdt2_term
Xdt3_term=dt3 * xdt3_term

DDDX=6 * xdt3_term
DDX xdt3_term + 2=6 * * xdt2_term
Dx=xdt3_term - xdt2_term dt + 3 * * (Points (1). X-ray Points (0). X)
X x=Points (0).

Pts (0). X=Points (0) x

X=x + 0.5
For I=1 To Npts
DDX=DDX + DDDX
Dx=dx + DDX
X=x + dx
Pts (I)=x x
Next I

'y incremental calculation
Ydt2_term=3 * (Points (2) * y - 2 Points (1), y + Points (0), y)
Ydt3_term=Points (3), y + 3 * (- Points (2) y + Points (1), y) - Points (0), y

Ydt2_term=dt2 * ydt2_term
Ydt3_term=dt3 * ydt3_term

Dddy=6 * ydt3_term
Ddy ydt3_term + 2=6 * * ydt2_term
Dy=ydt3_term ydt2_term + dt * 3 * (Points (1) y - Points (0), y)
Y=Points (0). The y

Pts (0), y=Points (0), y
Y=y + 0.5
For I=1 To Npts
Ddy=ddy + dddy
Dy=dy + ddy
Y=y + dy
Pts (I), y=y
Next I
End Sub

'the Bezier control point calculation
Private Sub DRC ()
Dim Tem (3) As the Vi, TemB As Double, JD (1) As a Double, the JDT (1) As a Double, t As Double, t2 (1) the As a Double
'the Bezier endpoint assignment
Points (0). X=PointsB (1) x
Points (0), y=PointsB (1) y
Points (3). X=PointsB (2) x
Points (3) y=PointsB (2) y

'to calculate the Bezier control point positionTem (0). X=PointsB (1). X-ray PointsB (0) x
Tem (0), y=PointsB (1) y - PointsB (0), y
Tem (1), x=Tem (0). X/Sqr (Tem (0). * Tem (0) in x x + Tem (0), y * Tem (0) in y)
Tem (0). X=PointsB (2) X-ray PointsB (1) x
Tem (0), y=PointsB (2) y - PointsB (1) y
Tem (1) y=Tem (0). X/Sqr (Tem (0). * Tem (0) in x x + Tem (0), y * Tem (0) in y)
T2 (0)=1: t2 (1)=1
For t=0 To 158
If t2 (0) & gt; Abs (Tem (1). X-ray CosNN (t)) Then
The JDT (0)=t/100
T2 (0)=Abs (Tem (1). X-ray CosNN (t))
End the If
If t2 (1) & gt; Abs (Tem (1) - CosNN y (t)) Then
The JDT (1)=t/100
T2 (1)=Abs (Tem (1) - CosNN y (t))
End the If
Next t
JD (0)=(Sgn (PointsB (0), y - PointsB (1) y) * JDT (0) + Sgn (PointsB (1) y - PointsB (2) y) * JDT (1))/2
"'" '
Tem (0). X=PointsB (3). X-ray PointsB (2) x
Tem (0), y=PointsB (3). The y - PointsB (2) y
Tem (1), x=Tem (0). X/Sqr (Tem (0). * Tem (0) in x x + Tem (0), y * Tem (0) in y)
Tem (0). X=PointsB (2) X-ray PointsB (1) x
Tem (0), y=PointsB (2) y - PointsB (1) y
Tem (1) y=Tem (0). X/Sqr (Tem (0). * Tem (0) in x x + Tem (0), y * Tem (0) in y)
T2 (0)=1: t2 (1)=1
For t=0 To 158
If t2 (0) & gt; Abs (Tem (1). X-ray CosNN (t)) Then
The JDT (0)=t/100
T2 (0)=Abs (Tem (1). X-ray CosNN (t))
End the If
If t2 (1) & gt; Abs (Tem (1) - CosNN y (t)) Then
The JDT (1)=t/100
T2 (1)=Abs (Tem (1) - CosNN y (t))
End the If
Next t
JD (1)=(Sgn (PointsB (2) y - PointsB (3) y) * JDT (0) + Sgn (PointsB (1) y - PointsB (2) y) * JDT (1))/2 + 3.14
TemB=(PointsB (2) X-ray PointsB (1), x)/2.82
'the Bezier control point assignment
Points (1), x=Cos (JD (0)) * TemB + PointsB (1) x
Points (1) y=- Sin (JD (0)) * TemB + PointsB (1) y
Points (2) x=Cos (JD (1)) * TemB + PointsB (2) x
Points (2) y=- Sin (JD (1)) * TemB + PointsB (2) y
Spline (vbBlue)
End Sub
'the Bezier map
Private Sub spline (color As Long)
Dim As Integer I
Dim As Long C
Calc_spline (64)
Picdraw. Scale (0, 300) - (200, 0)
For I=1 To 63
Picdraw. Line (Pts (I - 1) x, Pts (I - 1), y) - (Pts (I). X, Pts (I), y), color
Next I
Picdraw. Line (Pts (I - 1) x, Pts (I - 1), y) - (Pts (I). X, Pts (I), y), color
End Sub

'the Bezier call
Private Sub B1 (n As an Integer, st As Double)
Dim t As Integer
For t=0 To n - 4
PointsB (0), x (t)=Po x
PointsB (0), y=Po (t) y
PointsB (1), x (t + 1)=Po x
PointsB (1.) y=Po (t + 1) y
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  •  Tags:  
  • VBA
  • Related