# liang barsky clipping in homogeneous coordinates

This topic is 4692 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi! I'm trying to write line clipping in homogeneous coordinates, and now I've troubles with Liang Barsky algorithm I've also wrote sutherland clipping in homog. coords and it works perfectly but now I've troubles with computing intersections point for Liang Barsky. Clipper works only if both points have the same W. ps. sorry for my english..

##### Share on other sites
Clipping still works the same as in regular space. If (x',y',z') in eye space, and if the frustum has near N, far F, left L, right R, bottom B, and top L, then the homogeneous mapping is a point (x,y,z,w) where

x = 2*x'/(R-L) - (R+L)*z'/(N*(R-L)); |x| <= w
y = 2*y'/(T-B) - (T+B)*z'/(N*(T-B)); |y| <= w
z = F*(z'/N - 1)/(F-N); 0 <= z <= F/N
w = z'/N; 1 <= w <= F/N

For clipping purposes, you look only at the (x,y,w) values. Suppose the line segment is (1-t)*(x0,y0,w0) + t*(x1,y1,w1) for 0 <= t <= 1. Consider one of the frustum planes: x = w. If x0 < w0 and x1 > w1, then there must be a point (x,y,w) on the line segment for which x = w. Compute this by setting (1-t)*x0 + t*x1 = (1-t)*w0 + t*w1, so t = (w0-x0)/[(x1-x0)-(w1-w0)]. Say this point is (x(t),y(t),w(t)), where x(t) = w(t).

Is the problem that you are also trying to linearly interpolate the z-value? You cannot use a clip value of z(t) = (1-t)z0+t*z1 because of the "affine" term in the transformation from z' to z. If you were to linearly interpolate, the z-value at the point of intersection would be

z(t) = (1-t)*z0+t*z1 = N*[(1-t)*w0+t*w1] = N*w(t)

However, using the z' to z mapping once you have computed w(t), the correct value is

z(t) = F*(w(t) - 1)/(F-N)

Just a note. When clipping against all the planes one at a time, you should do the clipping against w = 1 first to avoid the "singularity" at the xyw-origin.

1. 1
Rutin
36
2. 2
3. 3
4. 4
5. 5

• 12
• 14
• 9
• 9
• 14
• ### Forum Statistics

• Total Topics
633345
• Total Posts
3011441
• ### Who's Online (See full list)

There are no registered users currently online

×