How to code a sin curve???? HELP!

R

reagan

I am trying to get a program(in visual C++) to draw a sine curve (from
0 to 2pi). It takes 8 lines to draw the complete curve. However, the
user can choose to use up to 100 lines to make the curve smoother. How
do I get the program to calculate that? I thought of using a counter
to count through until it gets to the number of user chosen lines
(m_iSample), but then I don't know how to calculate it. I just
finished trig too, darn it.

for (count = 0; count<=m_iSample; ++count) {
double iSinValue=sin(count * PI);//do the sin calculation
int iFinalSinValue=iSinValue * 200;//convert result so that it will
display correctly
pDC->LineTo( ??? , iFinalSinValue);//draw the line
}
 
A

adbarnet

Forgive me if my maths is not up to scratch - but isn't the value of the y
axis a function of the x axis, where x is the angle being 'sin'ed?
If so - your x-axis should be divided by the number of lines you want to
draw:

Point point(0,0);
Point newPoint(0,0);
for (int iPointIndex = 0; iPointIndex < m_iSample; ++iPointIndex)
{
x = 360/m_iSample; // You can do this relative to PI yourself...;-)

y = sin(x);

newPoint = (x,y)
drawLine (point, newPoint);
point = newPoint;
}
 
J

Jeremy A. Smith

your math is right, Y is a function of X
adbarnet said:
Forgive me if my maths is not up to scratch - but isn't the value of the y
axis a function of the x axis, where x is the angle being 'sin'ed?
If so - your x-axis should be divided by the number of lines you want to
draw:

Point point(0,0);
Point newPoint(0,0);
for (int iPointIndex = 0; iPointIndex < m_iSample; ++iPointIndex)
{
x = 360/m_iSample; // You can do this relative to PI yourself...;-)

y = sin(x);

newPoint = (x,y)
drawLine (point, newPoint);
point = newPoint;
}
 
R

reagan

Not exactly sure what you mean by Point. Are point and newPoint
objects? Sorry, dumb newbie questions, I know.
Forgive me if my maths is not up to scratch - but isn't the value of the y
axis a function of the x axis, where x is the angle being 'sin'ed?
If so - your x-axis should be divided by the number of lines you want to
draw:

Point point(0,0);
Point newPoint(0,0);
for (int iPointIndex = 0; iPointIndex < m_iSample; ++iPointIndex)
{
x = 360/m_iSample; // You can do this relative to PI yourself...;-)

y = sin(x);

newPoint = (x,y)
drawLine (point, newPoint);
point = newPoint;
}
 
R

reagan

Not exactly sure what you mean by Point. Are point and newPoint
objects? Sorry, dumb newbie questions, I know.
Forgive me if my maths is not up to scratch - but isn't the value of the y
axis a function of the x axis, where x is the angle being 'sin'ed?
If so - your x-axis should be divided by the number of lines you want to
draw:

Point point(0,0);
Point newPoint(0,0);
for (int iPointIndex = 0; iPointIndex < m_iSample; ++iPointIndex)
{
x = 360/m_iSample; // You can do this relative to PI yourself...;-)

y = sin(x);

newPoint = (x,y)
drawLine (point, newPoint);
point = newPoint;
}
 
R

reagan

Not exactly sure what you mean by Point. Are point and newPoint
objects? Sorry, dumb newbie questions, I know.
Forgive me if my maths is not up to scratch - but isn't the value of the y
axis a function of the x axis, where x is the angle being 'sin'ed?
If so - your x-axis should be divided by the number of lines you want to
draw:

Point point(0,0);
Point newPoint(0,0);
for (int iPointIndex = 0; iPointIndex < m_iSample; ++iPointIndex)
{
x = 360/m_iSample; // You can do this relative to PI yourself...;-)

y = sin(x);

newPoint = (x,y)
drawLine (point, newPoint);
point = newPoint;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top