I have writen a program that produce a list of coordinates that make up the profile of a gear wheel. I now want to show this profile on screen, I never done this before has anybody got any suggestions.
I've done quite a lot of drawing in VB. Its nit very fast, but it's easy. You can draw directly on a form or on(in?) a picturebox.
Set the autodraw property to true. I prefer to set the scael to vb pixels, but it's only importent if you want to control the extact size of the plot. Choose a scale for your drawing: MaxX, MaxY, MaxY, MinY in units of your drawing. Use the scaleWidth and Scale height (- your margins) to scale the plots.
Here's a little example.
------------------------------------------------------------
Option Explicit
Dim RightMarg As Integer, TopMarg As Integer, LeftMarg As Integer, BotMarg As Integer
Dim xo As Integer, yo As Integer, xps As Integer, yps As Integer
Dim Xmax As Single, Ymax As Single, Xmin As Single, Ymin As Single
Private Sub Form_Load()
Dim Data(1, 11) As String
Dim i As Integer, RemX As Single, RemY As Single
Dim XTmp As Single, YTmp As Single
'generate random data
For i = 0 To 11
Data(0, i) = Int(100 * Rnd)
Data(1, i) = 80 * Sin(i / 4) + 40 * Rnd + 10
Next i
'Find extremes
Xmin = 999999: Xmax = -999999
Ymin = 999999: Ymax = -999999
For i = 0 To UBound(Data, 2)
If Data(0, i) > Xmax Then Xmax = Data(0, i)
If Data(0, i) < Xmin Then Xmin = Data(0, i)
If Data(1, i) > Ymax Then Ymax = Data(1, i)
If Data(1, i) < Ymin Then Ymin = Data(1, i)
Next i
'Plot with lines
RemX = xo + ((Data(0, 0) - Xmin) / (Xmax - Xmin)) * xps
RemY = TopMarg + yps - ((Data(1, 0) - Ymin) / (Ymax - Ymin)) * yps
For i = 1 To UBound(Data, 2)
XTmp = xo + ((Data(0, i) - Xmin) / (Xmax - Xmin)) * xps
YTmp = TopMarg + yps - ((Data(1, i) - Ymin) / (Ymax - Ymin)) * yps
If XTmp >= LeftMarg And XTmp <= (Scalewidth - RightMarg) And _
YTmp >= TopMarg And YTmp <= (Scaleheight - BotMarg) Then Line (RemX, RemY)-(XTmp, YTmp)
RemX = XTmp
RemY = YTmp
Next i
End Sub
------------------------------------------------------------
It might seem a little overkill with all this scaling -but it pays back! e.g. if you want to zoom, simply change the scale (Xmax, Xmin, Ymax, Ymin) and plot again.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.