this is the last part of my a bit more complex homework which I can’t figure out myself.
Basically it’s a tangent function, drawn to SVG using C.
This is how I’m drawing it:

and this is how it should look like:

it’s pretty much the same except I’m drawing even those lines where tangent isn’t defined.. How do I get rid of that? I’m actually generating that tangent using a simple for cycle, and I understand by changing Lineto to Moveto I will get rid of those line, but how to determine a formula which will be usable for any height/width and any (-x,x) (-y,y). Any thoughts?
Source codes:
link to my drawing | link to original drawing
edit: structure
typedef struct svg_graph{
int w;
int h;
int x;
int y;
} graph;
and the code itself:
double initializer = 0;
double m = 0;
double temp = 0;
initializer = svg->h/2 - tan(-svg->x)*(((double)svg->h/2)/svg->y);
fprintf(output, "<path clip-path=\"url(#myClip)\" d=\"M 0 %.1f", initializer)
temp = ((double)svg->x/(svg->w/2));
m = svg->h/2 - tan(-svg->x+temp)*((double)(svg->h/2)/svg->y);
for (int i = 1; i<=svg->w; i++){
fprintf(output, " L %d %.1f", i, m);
temp = ((double)svg->x/(svg->w/2)) + temp;
m = svg->h/2 - tan(-svg->x+temp)*((double)(svg->h/2)/svg->y);
}
If the derivative is non-finite then you need a move rather than a line.