Any windows application to draw sine wave?

Hi,
I want to know if there is any windows application around (preferably freeware), which can draw sine waves easily (as a sort of built in function or block). Of course you can somehow manage to draw them with free hand tool in word, but this takes a lot of effort and the result is not usually satisfactory. Also there are some Math applications (like Matlab,...), but I didn't mean them, but a drawing application.

Thanx
parian061697Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mark2150Commented:
Sine function, or any other is trivial.

You plop a PictureBox on a form. In code you specify the .Scale property for 0-2Pi in X and +-1 in Y. THen you run a little loop:

FOR NDX = 0 to 2PI step .01
  PSET NDX, SIN(ndx)
NEXT NDX

This will plot the sine function for you.

Here is the source to a little test project I did. It has two forms SINE and TARGET. The target form has BorderStyle = 0 (none). The SINE form has three buttons on it, COMPUTE, PRINT and BYE It also contains a CommonDialog Control to enable printing. As written this is plotting tangents. Simply change the TAN function to SINE and it'll do sine plots.

Dim tgt As Object
Public pi2
Public radperd
Public spins As Integer

Private Sub Btn_Bye_Click()
'
Dim frm As Form
For Each frm In Forms
    Unload frm
Next frm
'
End
'
End Sub

Private Sub btn_compute_Click()
Set tgt = target
tgt.Width = pi2 * spins * 1280
tgt.Height = (tgt.Width / 4) * 3
Call plotit(tgt)
'
target.Show
End Sub

Private Sub btn_print_Click()
If Not armprinter Then GoTo drain
'
Set tgt = Printer
Call plotit(tgt)
'
drain:
End Sub

Public Function armprinter() As Boolean
'
' This function is used to determine if printing is required
' The big savings is that any form can call us and that
' particular form doesn't need a COMMONDIALOG object locally
' to determine if printing is switched on. This function returns
' a logical:
'
'   TRUE - Print
'   FALSE - Cancel
'
' Thus the caller can simply use:
'
'   if not armprinter then goto {abort label}
'
' Pretty slick, eh?
'
armprinter = True
On Error GoTo trapped
CommonDialog1.Flags = 0
CommonDialog1.CancelError = True
CommonDialog1.ShowPrinter
'
' We make it here then user said OK to print, pass default
' value back
'
GoTo drain
' =================
'
' Here on error trap of [Cancel], pass falsity back
'
trapped:
armprinter = False
Resume drain
'
drain:
End Function

Public Sub plotit(tgt As Object)
' tgt.ForeColor = vbGreen
' tgt.BackColor = vbBlack
'
If TypeName(tgt) <> "Printer" Then tgt.Cls
'
ygain = 10
tgt.ScaleHeight = 2
tgt.ScaleTop = -1
tgt.ScaleWidth = pi2 * spins
tgt.Line (0, tgt.ScaleHeight / 2)-(tgt.ScaleWidth, tgt.ScaleHeight / 2)
'
' outline
'
onedot = tgt.ScaleWidth / tgt.Width
tgt.DrawStyle = vbInsideSolid
'
'tgt.Line (0, tgt.ScaleTop)-(tgt.ScaleWidth, tgt.s)
'tgt.Line (0, 0)-(tgt.ScaleWidth, 0)
'tgt.Line (0, 0)-(tgt.ScaleWidth, 0)
'tgt.Line (0, 0)-(tgt.ScaleWidth, 0)

'
'tgt.Line (0, tgt.ScaleTop)-(tgt.ScaleWidth - onedot, tgt.ScaleTop + tgt.ScaleHeight - onedot), , B
'
tgt.DrawStyle = vbDot
tgt.Line (0, 0)-(tgt.ScaleWidth, 0)
'
' Draw hacks
'
tgt.DrawStyle = vbDash
For x = 0 To pi2 * spins Step pi2 / 4
    tgt.Line (x, tgt.ScaleTop)-(x, tgt.ScaleTop + tgt.ScaleHeight)
Next x
tgt.DrawStyle = vbSolid
tgt.Line (0, tgt.ScaleTop)-(0, tgt.ScaleTop + tgt.ScaleHeight)
'
If TypeName(tgt) <> "Printer" Then
'    For x = 0 To tgt.ScaleWidth
'        For y = 0 To tgt.ScaleHeight
'            tgt.Line (x - 0.05, y)-(x + 0.05, y)
'            tgt.Line (x, y - 0.05)-(x, y + 0.05)
'        Next y
'    Next x
End If
'
originx = 0         'Graph start
originy = 0
'originy = tgt.ScaleHeight / 2

On Error GoTo oopstrap
'
oneangle = pi2 * spins / tgt.Width
xdelta = tgt.ScaleWidth / tgt.Width
yScale = tgt.ScaleHeight / (2 * ygain)
'yoffset = tgt.ScaleHeight / 2
yoffset = 0
For angle = 0 To pi2 * spins Step oneangle
    newx = originx + xdelta
'
' We should trip the "undefined" error trap here now & again
'
    newy = Tan(angle) * yScale + yoffset
    '
    ' Didn't cause error - skip trap
    '
    GoTo patch
' =================
'
' Caught error trap draw vert line instead
'
oopstrap:
        Resume oopstrap1
' ===================
'
' No fall thru here
'
oopstrap1:
    tgt.DrawStyle = vbdashed
    tgt.Line (newx, 0)-(newx, tgt.ScaleHeight)
    tgt.DrawStyle = vbSolid
'
patch:
    If newy < tgt.ScaleTop Or newy > tgt.ScaleTop + tgt.ScaleHeight Then
    Else
        tgt.Line (originx, originy)-(newx, newy)
    End If
    originx = newx
    originy = newy
Next angle
'
GoTo drain
drain:
If TypeName(tgt) = "Printer" Then tgt.EndDoc
'
End Sub

Private Sub Form_Activate()
'
' define constants
'
pi2 = (4 * Atn(1)) * 2   'No intrinsic "pi" function - @#$%^ idiots!
radperd = Atn(1) / 45
spins = 1           'Cycles to plot
End Sub


0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
parian061697Author Commented:
Dear mark2150, I really appreciate your answer, but I am not that experienced in this buisness, so I would like to know which program are you talking about.  (I assumed that it was word, so I went to its help and searched for "picture box", but there was no match). So I don't know how to insert a picture box to start with. I would also appreciate it if you tell me where I shall write my code.
   
0
mark2150Commented:
Visual Basic is what we're using here...

M
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

parian061697Author Commented:
I don't have visual basic on my computer installed, so I have to try it on Tuesday on another computer, and ask for your help if something comes up. So let's get back to this in a few day's time.  
0
mark2150Commented:
Ok. What exactly do you need? Are you just trying to make illustrations for a text or somesuch? If so I can capture the images here and email them to you if you want. Write me direct at the address in my profile.

M
0
impact2Commented:
if you just have to draw a sine wave for a document you can use the curve tool in word...
to be able to use it, check out the Drawing toolbar, then click the Autoshapes option, then Lines, finally the Curve button... this is more convinient than the freehand tool...
sorry but i can't think of a drawing application w/c has a built-in function to draw sine waves... but if you want a more accurate drawing try-out visio, photoshop or any other drawing application were you can use gridlines. more often than not those applications have curve or arc tools...

hope i helped...
0
parian061697Author Commented:
I got the files. Thanks a lot.
0
parian061697Author Commented:
For impact2: I have already got what I wanted via e-mail, but thanks for your help any way.
0
mark2150Commented:
I modified the above code to use the sin() function instead of tan and jumped around the code that drew gridlines. Setting the SPINS=5 gave me five complete sine wave cycles on the screen. A quick <Alt PrtSc> and paste into PhotoEditor got the file and then all I did was save into .BMP and .JPG. Piece of cake.

impact2, trying to freehand an *accurate* sine wave with curves or arcs would be a NIGHTMARE. You'ld have to bump up to MathCAD or somesuch to be able to pull trig. I had written the above module to solve the same problem that parian was having. I was writing a technical paper and needed a family of tangent curves and there was just no way to get nice, crisp, "textbook" quality trig functions.

M
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Graphics Software

From novice to tech pro — start learning today.