Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Graphical Display 1

Status
Not open for further replies.

mhall

Technical User
Sep 26, 2000
13
GB
Hi

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.

Thanks

Matt


 
Hi,

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

AutoRedraw = True
ScaleMode = vbPixels
ForeColor = vbBlack
AutoRedraw = True
BackColor = vbWhite
RightMarg = 10: TopMarg = 10: LeftMarg = 10: BotMarg = 10

'Origon definition
xo = LeftMarg
yo = Scaleheight - BotMarg
'plot scale definition
xps = Scalewidth - RightMarg - LeftMarg
yps = Scaleheight - TopMarg - BotMarg

'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.

Good luck
:) Sunaj
 
Thanks

this is exactly what I want

 
Maybe a little ' Let sunaj know the post was helpful' for me?
:-9Sunaj
 
*copies the code for future use*

Here you go, Sunah ;)
&quot;Much that I bound, I could not free. Much that I freed returned to me.&quot;
(Lee Wilson Dodd)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top