Question

I'm trying to draw something like a coordinate system on my screen. I'm having a centre and four lines going from it.The vertical line is straight as is the horizontal line, right hand (dividing the first and second quadrant). But the horizontal line, left hand, is not continuous - it goes one pixel up at the half of the line.I don't understand this, because the left horizontal line is axisymmetric the the right one. The line-drawing is done with sin,cos and pi, which i defined for more than ten digits.

Here is the code:

int Mx=300;
int My=300;
/* vertical line*/
XDrawLine(dis,win,gc, Mx, My, Mx+sin(0)*250   , My+cos(0)*250);//line down
XDrawLine(dis,win,gc, Mx, My, Mx-sin(0)*250   , My-cos(0)*250);//line up
/*horizontal line */
XDrawLine(dis,win,gc, Mx, My ,Mx+sin(pi/2)*250, My+cos(pi/2)*250);//line right 
XDrawLine(dis,win,gc, Mx, My, Mx-sin(pi/2)*250, My-cos(pi/2)*250);//line left 

And here is a example picture of what i meant -axis of abscissas

How does the X Window system locate pixels at all - may it differ from display to display?

Was it helpful?

Solution

There's nothing wrong with Xlib, it's just a rounding error.

My-cos(pi/2)*250

when cast to an int, evaluates to 299.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top