Specify individually the translation and scaling matrices required to transform a 2D window of [Xmin=-234, Ymin=156] and [Xmax=66, Ymax=456] to a display viewport of [Umin=45, Vmin=35] and [Umax=245, Vmax=185].

Ignore the question above since I solved the matrix, the information is just relevant for the question I'm stuck on

I was asked to compute the view-port positions (U1,V1) and (U2,V2) for two points A (-100,300) and B (30,-40) in a 2D window and determine if these two points are inside the view-port.

Based on the transformation Matrix I found (U1,V1) to be (403/3, 407) and (U2,v2) to be (221, -103). It turns out that both these points are outside our view-port but part of the line between them is inside.

Now I'm confused about this part below:

Apply a 2D clipping method to the line segment between the two points A and B as given in above.

My Attempt

delta x = 221-(403/3) = 260/3

delta y = -103 - 406 = -510

m = delta y / delta x = -5.88

I started with U1,V1 since it is above our viewport:

Y = 185

X = 403/3 + (185-407)*(delta x/ delta y)

X = 279.48

Point 1 - (172, 185)

Is this correct? Since the point is now within the view-port. Do I then do the same for the second point?


Taken from Wikipedia's article on Cohen-Sutherland:

Both endpoints are in different regions: in case of this nontrivial situation the algorithm finds one of the two points that is outside the viewport region (there will be at least one point outside). The intersection of the outpoint and extended viewport border is then calculated (i.e. with the parametric equation for the line), and this new point replaces the outpoint. The algorithm repeats until a trivial accept or reject occurs.

So yes, since your new first point is inside the viewport, but your second point is outside, the situation is non-trivial (i.e. no "go render it all" or "go discard it all"), it will repeat with the second point. Afterwards, both points will be inside the viewport, therefore it is a trivial draw and no further action is needed.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.