Be seen. Boost your question’s priority for more expert views and faster solutions

Hi experts,

I have an Array that contains x and y coordinates. I need to draw a curve

through those coordinates. But I have no idea how to do that , I tried using bezier curves but that didn't seem to work.

I'm a vb.net newbe so be gentle

K.

I have an Array that contains x and y coordinates. I need to draw a curve

through those coordinates. But I have no idea how to do that , I tried using bezier curves but that didn't seem to work.

I'm a vb.net newbe so be gentle

K.

Overloads Public Sub DrawCurve(Pen, Point())

Bob

for an s -curve you need a cubic spline.

Can I just cut and paste this ? Because I don't think I have the brainpower to figure this out.

Do you have any friends ? ;-)

and you ofcourse you need to adjust the x and y declarations to the number of point you have

Dim x(4) As Single

Dim y(4) As Single

and fill them with your own coordinates.

Want do you mean if I have any friends

And what I meant was, if you can figure out these things you won't have much spare time or your brilliant . ;-)

Thanks RonaldBiemans, you are truely an expert.

And thanks to TheLearnedOne too.

Bob

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.

Dim x(4) As Single

Dim y(4) As Single

Dim y2() As Single

Dim yout As Single

Dim ron As Graphics

Private Sub spline(ByVal x() As Single, ByVal y() As Single, ByVal n As Integer, ByVal yp1 As Single, ByVal ypn As Single)

Dim i, k As Integer

Dim p, qn, sig, un, u() As Single

ReDim y2(n)

ReDim u(n)

If yp1 > 9.9E+29 Then

y2(0) = u(0) = 0.0

Else

y2(0) = -0.5

u(0) = (3.0 / (x(1) - x(0))) * ((y(1) - y(0)) / (x(1) - x(0)) - yp1)

End If

For i = 1 To n - 1

sig = (x(i) - x(i - 1)) / (x(i + 1) - x(i - 1))

p = sig * y2(i - 1) + 2

y2(i) = (sig - 1) / p

u(i) = (y(i + 1) - y(i)) / (x(i + 1) - x(i)) - (y(i) - y(i - 1)) / (x(i) - x(i - 1))

u(i) = (6 * u(i) / (x(i + 1) - x(i - 1)) - sig * u(i - 1)) / p

Next i

If ypn > 9.9E+29 Then

qn = un = 0.0

Else

qn = 0.5

un = (3.0 / (x(n) - x(n - 1))) * (ypn - (y(n) - y(n - 1)) / (x(n) - x(n - 1)))

End If

y2(n) = (un - qn * u(n - 1)) / (qn * y2(n - 1) + 1)

For k = n - 1 To k >= 1 Step -1

y2(k) = y2(k) * y2(k + 1) + u(k)

Next

End Sub

Private Function splint(ByVal xa() As Single, ByVal ya() As Single, ByVal y2a() As Single, ByVal n As Integer, ByVal x As Single)

Dim klo, khi, k As Integer

Dim h, b, a As Single

klo = 0

khi = n

Do While khi - klo > 1

k = khi + klo >> 1

If xa(k) > x Then

khi = k

Else

klo = k

End If

Loop

h = xa(khi) - xa(klo)

a = (xa(khi) - x) / h

b = (x - xa(klo)) / h

yout = a * ya(klo) + b * ya(khi) + ((a ^ 3 - a) * y2a(klo) + (b ^ 3 - b) * y2a(khi)) * (h ^ 2) / 6

Return yout

End Function

Private Sub spline_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

x(0) = 100

x(1) = 200

x(2) = 300

x(3) = 400

x(4) = 500

y(0) = 300

y(1) = 330

y(2) = 200

y(3) = 300

y(4) = 200

spline(x, y, 4, 0, 0)

End Sub

Private Sub Panel1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.Paint

Dim Xrange As Single

Dim Yrange As Single

Xrange = Panel1.Width / (x(4) + 100)

Yrange = Panel1.Height / (y(1) + 100)

ron = Panel1.CreateGraphics

For br As Single = x(0) To 500 Step 0.1

ron.DrawRectangle(New Pen(Color.Black), br * Xrange, splint(x, y, y2, 4, br) * Yrange, 1, 1)

For bf As Integer = 0 To x.GetUpperBound(0)

ron.FillEllipse(New System.Drawing.SolidBrush(

Next

Next

End Sub