# Plotting Damped Cosine Functions

Hi guys,

Recently we were told in class to work on an assignment in which we were supposed to plot some engineering functions. There were several of them, so I am only taking the cosine one as an example.
We were supposed to write and call several functions that would take real life coordinates and then map them into pixel coordinates, as well as get y values based on given arrays of x values.
I think I did okay with the functions, but now that they are all written out, I have no idea what function to use in draw to be able to actually draw this cosine function.
Here are my functions for plotting points and mapping:
int getXSamples(float xmin, float xmax, float step, float x[])
{
int n;
n = (xmax - xmin) / step + 1;
for (int i = 0; i < n; i++)
{
x[i] = xmin + i * step;
}
return n;
}

void getDampedCosSamples(int n, float x[], float y[], float alpha, float w)
{

``````for (int i = 0; i < n; i++)
{
y[i] = exp(-alpha * x[i])*cos(w*x[i]);
}
``````

}
float map(float in, float inMin, float inMax, float outMin, float outMax)
{
float m, b, out;

``````m = (outMax - outMin) / (inMax - inMin);
b = outMax - m * inMax;
out = m * in + b;
return(out);
``````

}
void map_vec(int n, float in[], float out[], float inMin, float inMax, float outMin, float outMax)
{
float m, b;

``````m = (outMax - outMin) / (inMax - inMin);
b = outMax - m * inMax;

for (int i = 0; i < n; i++)
{
out[i] = m * in[i] + b;
}
``````

}
I basically want an advice on how I can go ahead and call those functions properly in what draw function to be able to just map this cosine curve. I will appreciate any help I can get.

You can easily start experimenting with some drawing, in the draw() function. I would use ofDrawLine(), drawing the graph as a series of segments, or better an ofPolyline with the coordinates you need.

Unless you do some coordinate transformations the origin is located at the screen top left, with the Y axis pointing downwards.

regards
Davide