Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!zaphod.mps.ohio-state.edu!julius.cs.uiuc.edu!ux1.cso.uiuc.edu!ux1.cso.uiuc.edu!m.cs.uiuc.edu!sunc5!mcooper From: mcooper@sunc5.cs.uiuc.edu Newsgroups: comp.graphics Subject: cartesian to spherical Message-ID: <23900019@sunc5> Date: 28 Sep 90 20:09:00 GMT Lines: 54 Nf-ID: #N:sunc5:23900019:000:1833 Nf-From: sunc5.cs.uiuc.edu!mcooper Sep 28 15:09:00 1990 The answer's staring me in the face for this one, but I seem to have gone blind. Keep in mind that this is on a SGI PI, so the fhypot etc. are valid for floats.. I'm trying to write a routine that will draw a cylinder in an arbitary position in an arbitrary orientation. I have a cylinder object created, with one end centered at the origin, and the other at (1.0, 0.0, 0.0). the routine should accept two endpoints, rotate the cylinder to the proper angle, and translate it to the proper position. I've hit a dead end in my efforts. I pass the routine two endpoints, (x1,y1,z1) and (x2,y2,z2). to get my phi and theta angles, (and rho, for length), I use the following equations with x = x2-x1, y = y2-y1, z = z2 - z1: rho = fhypot(x, fhypot(y, z)); theta = fatan2(z, x); phi = facos2(y, *rho); I have also tried phi = fatan2(y, fhypot(z,x)); But nothing seems to work quite right. Incidentally, I'm performing the operations as follows: pushmatrix(); translate(x2,y2,z2); rot(theta,'y'); rot(phi,'z'); scale(rho, 1.0, 1.0); popmatrix(); The scaling and translation seem to work fine. the rotations are a mess. Any help is appreciated. Note the different email address in the .sig.. Thanks. +-------------------------------------+---------------------------------------+ | "When the going gets weird, | Marc Cooper marcc@ncsa.uiuc.edu | | the weird turn pro." | | | | National Center for Supercomputing | | -Hunter S. Thompson | Applications | +-------------------------------------+---------------------------------------+ | The above opinoins are my own, and do not reflect those of NCSA. *Yawn* | +-----------------------------------------------------------------------------+