VB icon

Plotting sine, cosine and tangential waveforms

Email
Submitted on: 1/2/2015 6:27:00 PM
By: Shahab Faruqi (from psc cd)  
Level: Intermediate
User Rating: By 3 Users
Compatibility: C++ (general)
Views: 548
 
     This program is part of a larger project; one which involves plotting the curve for any given eqyuation. If someone wants to develop that program jointly with me, or has any useful tip concerning it please email me. Meanwhile check out this program...
 

INCLUDE files:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
//**************************************
//INCLUDE files for :Plotting sine, cosine and tangential waveforms
//**************************************
#include<math.h>
#include<stdlib.h>
#include<graphics.h>
#include<conio.h>
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: Plotting sine, cosine and tangential waveforms
// Description:This program is part of a larger project; one which involves plotting the curve for any given eqyuation. If someone wants to develop that program jointly with me, or has any useful tip concerning it please email me.
Meanwhile check out this program...
// By: Shahab Faruqi (from psc cd)
//**************************************

/*
Author: Shahab Faruqi
Dated: 17 September 2001
Description: This program calculates sine, cosine and tangent waveforms.
You can adjust the frequency and amplitude of the waves by
changing the 2 arguments to sinewave(), cosinewave() and
tanwave() functions.
NOTE: Your graphics library must be installed. All *.bgi and
*.chr files must be located in the c:\tc\bgi directory. If
they are situated elsewhere change the location in the
initgraph() function.
Copyright: Public Domain
*/
#include<math.h>
#include<stdlib.h>
#include<graphics.h>
#include<conio.h>
double x=0,sinx,cosx,tanx,multi;
int ay,ax,newx=0,ox,oy,maxx,maxy,midy;
void sinewave(int,int);
void cosinewave(int,int);
void tanwave(int,int);
int distance(double,double);
int distance_tan(double,double);
void sinewave(int xmult,int ymult)
{
x=0;
newx=0;
ox=oy=0;
maxx=getmaxx();
midy=getmaxy()/2;
while(newx<maxx)
{
while(1)
{
if(x>3.142)
break;
sinx=sin(x);
multi=sinx*ymult;
ay=multi;
ax=newx+x*xmult;
moveto(ox,midy-oy);
lineto(ax,midy-ay);
x+=0.01;
ox=ax;
oy=ay;
}
newx=ax;
x=0;
while(1)
{
if(x>3.142)
break;
sinx=sin(x);
multi=sinx*ymult;
ay=multi;
ax=newx+x*xmult;
moveto(ox,midy+oy);
lineto(ax,midy+ay);
x+=0.01;
ox=ax;
oy=ay;
}
newx=ax;
x=0;
}
}
void cosinewave(int xmult,int ymult)
{
x=0;
newx=0;
ox=oy=0;
maxx=getmaxx();
midy=getmaxy()/2;
while(newx<maxx)
{
while(1)
{
if(x>3.14000)
break;
cosx=cos(x);
multi=cosx*ymult;
ay=multi;
ax=newx+x*xmult;
moveto(ox,midy-oy);
if(distance(ax,midy-ay)==0)
lineto(ax,midy-ay);
x+=0.01;
ox=ax;
oy=ay;
}
newx=ax;
x=0;
while(1)
{
if(x>3.1420)
break;
cosx=cos(x);
multi=cosx*ymult;
ay=multi;
ax=newx+x*xmult;
moveto(ox,midy+oy);
if(distance(ax,midy+ay)==0)
lineto(ax,midy+ay);
x+=0.01;
ox=ax;
oy=ay;
}
newx=ax;
x=0;
}
}
void tanwave(int xmult,int ymult)
{
x=0;
newx=0;
ox=oy=0;
maxx=getmaxx();
midy=getmaxy()/2;
while(newx<maxx)
{
while(1)
{
if(x>3.14000)
break;
tanx=tan(x);
multi=tanx*ymult;
ay=multi;
ax=newx+x*xmult;
moveto(ox,midy-oy);
if(distance_tan(ax,midy-ay)==0)
lineto(ax,midy-ay);
x+=0.01;
ox=ax;
oy=ay;
}
newx=ax;
x=0;
while(1)
{
if(x>3.1420)
break;
tanx=tan(x);
multi=tanx*ymult;
ay=multi;
ax=newx+x*xmult;
moveto(ox,midy+oy);
if(distance_tan(ax,midy+ay)==0)
lineto(ax,midy+ay);
x+=0.01;
ox=ax;
oy=ay;
}
newx=ax;
x=0;
}
}
int distance(double x,double y)
{
int xx=getx(),yy=gety();
double r;
x-=xx;
y-=yy;
x*=x;
y*=y;
r=sqrt(x+y);
if(r>1.0)return 1;
else return 0;
}
int distance_tan(double x,double y)
{
int xx=getx(),yy=gety();
double r;
x-=xx;
y-=yy;
x*=x;
y*=y;
r=sqrt(x+y);
if(r>100.0)return 1;
else return 0;
}
void main()
{
int a=DETECT,b;
initgraph(&a,&b,"c:\\tc\\bgi");
setlinestyle(0,0,1);
setcolor(14);
line(1,0,1,getmaxy());
line(1,getmaxy()/2,getmaxx(),getmaxy()/2);
sinewave(30,100);/*Change the arguments to change the frequency and
amplitude of the wave respectively*/
getch();
cleardevice();
line(1,0,1,getmaxy());
line(1,getmaxy()/2,getmaxx(),getmaxy()/2);
cosinewave(30,100);/*Change the arguments to change the frequency and
amplitude of the wave respectively*/
getch();
cleardevice();
line(1,0,1,getmaxy());
line(1,getmaxy()/2,getmaxx(),getmaxy()/2);
tanwave(30,100);/*Change the arguments to change the frequency and
amplitude of the wave respectively*/
getch();
closegraph();
}


Other 6 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.