PDA

View Full Version : Finding the 2D XY Coordinates for Cylinder Extrema

Clayton
01-29-2004, 02:36 PM
I am attempting to find the top, bottom, left, and right extremes in two dimensional screen coordinates for a cylinder that has been rotated and possibly translated. I am assumming I should do some vector mathw but I'm net sure exactly what or how. Any ideas? Thanks.

endash
01-30-2004, 08:05 AM
You might try using the Modelview Matrix. See page 98 of the Red Book.

GLfloat matrix[16];
glGetFloatv(GL_MODELVIEW_MATRIX, matrix);

And remember, the matrix is in this order:

matrix[0],matrix[4],matrix[8],matrix[12],
matrix[1],matrix[5],matrix[9],matrix[13],
matrix[2],matrix[6],matrix[10],matrix[14],
matrix[3],matrix[7],matrix[11],matrix[15]

Clayton
02-05-2004, 11:31 AM
I'm not quite sure what you intend for me to do using the modelview matrix, perhaps you can explain?

endash
02-05-2004, 12:53 PM
Manually multiply your vertex position by the modelview matrix. That should tell you where it gets projected, I think.

That may not be enough, though... I'm kinda fuzzy on it, actually. There's more that happens before things hit the screen (in particular, the projection matrix, perspective division, and the viewport transformation -- looking at the red book page 98).

Why do you need to know?

Clayton
02-05-2004, 01:57 PM
Unfortunately, I don't need to find where the Extrema have gone after translation, I need to find the new extrema, post translation. This may involve finding those points ahead of time (untranslated) then using gluProject, but I'm not sure.

dovkruger
02-05-2004, 06:14 PM
This is for arbitrary rotations? That's somewhat hard. Let's start by doing one orientation at a time.

If the cylinder is vertical, centered on (0,0,0) with a height h and radius r, then:

xmax = r, xmin = -r
ymax = h/2, ymin = -h/2
zmax = r, zmin = -r

if the cylinder is rotated around the z axis clockwise, the center of the cylinder would be:

x = h/2 cos a, y = h/2 sin a

the rightpoint point would be straight down the top of the cylinder to the right:

x2 = x + r sin a, y2 = y- r cos a

the highest point would be:

x3 = x - r sin a, y2 = y + r cos a

etc.

Continue for each rotation. You can presumably do it all by multiplying matrices, as this is a standard transformation.

Slight correction:
If you rotate in x, then in y, then in z, say, the point that was originally highest in x may not be highest after y. So this is an approximation, not a perfect answer. The correct answer is that as you rotate about z, then about x, the highest point rotates around the circle. The direction should be normal to the normal to the top of the cylinder, with the maximum upward slope. It should be fairly easy to find with some thought....

[This message has been edited by dovkruger (edited 02-05-2004).]