# 3D Cohen-Sutherland Clipping Algorithm

2 replies [Last post]
lordflasheart
Offline
Joined: 2006-06-28

Hi,

I've been redirected here from the Sun forums. I'm a distance learner and am taking a module on Computer Graphics whereby I have to provide Java code to twenty questions all of which cannot use inherent classes. The only thing I can use is drawRect in order to draw a pixel :-(

I have answered a question on 2D clipping using Cohen-Sutherland algorithm but I am having real problems trying to extend it to 3D. Here I have to clip a line segment from (x1, y1, z1) to (x2, y2, z2) against a canonical view volume, a cuboid from (-1, -1, 0) to (1, 1, 1). I appreciate that the outcodes have been extended to include front and behind. It is just how to divide the lines up in order to clip.

Any pointers would be welcome.

Chris

geoman
Offline
Joined: 2006-06-28

are your lines to be clipped on a plane?
then you can reduce your problem to 2D by doing the clipping on that plane.
thanks

Alessandro Borges

Of course you will find a lot of stuff about it, as well java code, but the best source are books as "Calculus with Analytic Geometry", Louis Leithold, and "Introduction to Computer Graphics",James D. Foley, the #1 3D reference.

For fast code just Google: line plane intersection java

I've been redirected here from the Sun forums. I'm a distance learner and am taking a module on Computer Graphics whereby I have to provide Java code to twenty questions all of which cannot use inherent classes. The only thing I can use is drawRect in order to draw a pixel :-(

I have answered a question on 2D clipping using Cohen-Sutherland algorithm but I am having real problems trying to extend it to 3D. Here I have to clip a line segment from (x1, y1, z1) to (x2, y2, z2) against a canonical view volume, a cuboid from (-1, -1, 0) to (1, 1, 1). I appreciate that the outcodes have been extended to include front and behind. It is just how to divide the lines up in order to clip.

Any pointers would be welcome.