#37853 - zorpax - Thu Mar 17, 2005 10:54 pm
Hi, I'm new to computer graphics, and am trying to draw lines!
I am stuck on how line clipping works. If the line has one end on screen and one end off screen, I simply do a binary search to find the screen edge.
But how do you clip a line which has both ends off the screen? when cohen sutherland says that the line 'may' be on screen, how do you tell if it is actually on the screen?
any help would be great
Thanks
#37860 - zorpax - Thu Mar 17, 2005 11:27 pm
just worked out one way of doing it.
it i recursively split the line in 2 and draw both halves, it overcomes my problem
but there must be a faster way
#37862 - wintermute - Thu Mar 17, 2005 11:34 pm
#37863 - zorpax - Thu Mar 17, 2005 11:37 pm
yeah, i get that. the question is, how do you find the intersection of the line and the edge of the screen. I assume that binary search will be faster than algebra
am i wrong here?
#37864 - wintermute - Thu Mar 17, 2005 11:52 pm
#37865 - zorpax - Fri Mar 18, 2005 12:01 am
ok, yes i got that.
but if both ends are off screen, then it is quite possible to take the mid point and that still to be off screen. the question is, which end do you discard?
#37866 - wintermute - Fri Mar 18, 2005 12:14 am
for the line not to have been trivially rejected already the line must cross the boundary you're clipping against - one side of the line is 'inside' and one side is 'outside'. Try to visualise it with the applet - you reject the end of the line on the 'outside' of the boundary line.
#37868 - zorpax - Fri Mar 18, 2005 12:35 am
i see, so you clip it against the infinite line running along the bottom of the screen. not against the actual bottom of the screen
makes sense now
thanks
#37879 - quonic - Fri Mar 18, 2005 5:03 am
What Highschool class was it? Oh yeah Algebra...
y = mx + b
or...
m = (y2 - y1) / (x2 - x1)
Simple math
_________________
Comming Soon: http://www.spyingwind.com
#37881 - wintermute - Fri Mar 18, 2005 6:35 am
quonic wrote: |
What Highschool class was it? Oh yeah Algebra...
y = mx + b
or...
m = (y2 - y1) / (x2 - x1)
Simple math |
well done, now go back and read the discussion that finished hours ago
#37923 - Miked0801 - Fri Mar 18, 2005 7:22 pm
Quote: |
What Highschool class was it? Oh yeah Algebra...
y = mx + b
or...
m = (y2 - y1) / (x2 - x1)
|
Can't help myself...
If you are advocating the drawing and clipping of lines using the above equations, go to Jail, do no pass go, do not collect your High School diploma. Hmmm, let's see. Let's do a divide to get every single pixel position on the line - hope it doesn't have a slopelarger than one or it will look real crappy - oh and, lets solve a simultaneous system of equations to get the clipping point while we're at it.
While Wintermute added insightful and usefullknowledge (and links!), your quip adds nothing and makes you look like an^h^h^h^h^h^h (censored) silly.
#37979 - zorpax - Sat Mar 19, 2005 4:41 pm
right, i'm bored of line clipping,
any one got some example code?
mine ends up about 100 lines long
cheers