RenderMan & RISpec >> trouble with rotating a cylinder

by kedmond » Mon, 18 May 2009 06:44:19 GMT

I'm trying to write a program that will take two sets of coordinates
in space A = [x1, y1, z1] and B = [x2, y2, z2] and then draw a
cylinder between the two of them.

I am having a surprisingly hard time of expressing this calculation in
Renderman.

For example, I made a sphere that is at [0, 0, 0] and another at [1,
1, 1].

If a horizontal line were drawn through the [0, 0, 0] sphere and a
vector drawn to [1, 1, 1] then the angle would be around 35 degrees,
while the angle between the line and the x-axis is 45 degrees.

I guess I'm not sure how to make Renderman render this configuration.
I've tried the following:

TransformBegin
Rotate -35 1 0 0
Rotate -45 0 1 0
Rotate 0 0 0 1

Translate 0 0 0
Cylinder 0.2 0 5 360
TransformEnd

Of course, this does not work. Any help would be greatly appreciated.

-Kazem

RenderMan & RISpec >> trouble with rotating a cylinder

by kedmond » Mon, 18 May 2009 12:49:13 GMT


Nevermind! I just found an online copy of Malcolm Kesson's 1994
introductory book on Renderman. In it, he explains how the order of
the operations is crucial. I had no idea Renderman computed the
transformations in reverse order from when the object is declared. I
guess you'd call it a LiFo.

-kedmond

RenderMan & RISpec >> trouble with rotating a cylinder

by Olivier3001 » Thu, 21 May 2009 21:26:06 GMT


By the way, the best method to do that is not with rotations but with
a change of basis. Compute the following vectors:

Z = (B - A)
Y = any vector which is perpendicular to Z
X = Y x Z (cross product)

then normalize X and Y (to not change the radius of your cylinder) and
build a transformation matrix using the 3 vectors as rows (or columns,
depending which way the matrices are used). I assumed here that the
original cylinder had its length along the Z axis. If not, you need to
swap the vectors.

To pick a vector V which is perpendicular to W, use:
V = (0, Wz, -Wy) if |Wx| < |Wy|
V = (-Wz, 0, Wx) otherwise

You can easily verify that V.W (the dot product) is always zero. The
two cases are so V is never (0,0,0) if W isn't.

Olivier

Similar Threads

1. Rotate a Cylinder in the direction of a Vector

2. I can't free rotate word art, can only rotate 90 degrees or flip

When adding Word Art to a document, I'm not able to "free rotate" the 
inserted word art.  The "free rotate" in the Draw menu is grayed out.

3. Rotate a 3D mesh without rotate axes

4. difference between convert -rotate and gimp/rotate

5. Rotate the graphics without rotate the text in SVG

6. 3D Rotate or Pseudo Rotate

Greetings,

Hoping for some help here. I've got a project in which I'm trying to add 
a feature to.

I've been searching the web all weekend for a simple (or not so simple, 
but easy to understand) solution to no avail.

I'm using VB6 on WindowsXP. What I have is an image. I'd like to take the 
image and do a 3D projection of it, like it was sitting the side of a 
cube.

Looking at DX and GDI+ and not really sure how it can be done. I don't 
really need to rotate it at all once it's created, just to create it one 
time projected on a 3D plane.


**************              *  **     
*            *      * *  *      *
*            *      *           *
*            *      *           *
*            *      *           *
*            *      * *         *
*            *           *      *
**************              *   *

(Well the ASCII 'Art' didn't work out to well.)

Image detail is not that important, as it's just going to be a thumbnail 
of sorts, that will only be like 1/10th the size of the original image.

Thanks in advance,

DanS

7. Rotate text along with rotating rectangle

8. Word 2003 text does not rotate when drawing shape is rotated

Fix it. It should work the same as in PowerPoint. So much for cross 
application compatibility.