Of course, it seems dot product formulation u dot v = 0 seems straight forward enough in computing an orthogonal vector. The problem is that there can be a lot of different orientations for a given orthogonal vector, and thus many different solutions to the same problem (I'd have an infinite number of solutions, for instance, rotated around the plane of r and z defined by angle phi on the set of reals with 2 solutions matching the given plane). So one approach that I've considered, not sure if its a bit lengthy but at least it provides a bit of user control in the direction choosing aspect of an orthogonal vector. Is in using a bit of trigonometry. Lets say, in a given coordinate system we knew the direction of r(x,y) by its angle theta, and on the z plane its angle between r and z given by phi. Then we could do a bit of work in three dimensions with these angles by adding say 90 degrees to a given angle and then recomputing for the new given direction of r or z, a given set (x,y,z) coordinates. Another solution, that I have found is using a bit of linear algebra and using a rotation of coordinates system, where rotating our coordinate plane xz to match the angle of phi. Where under the new coordinate system we have the vector now occupying a two dimensional plane. In this case finding an orthogonal vector, at least in theory, sounds a bit easier, here we have our coordinate plane matched to the angle between r and z which means that we aren't merely computing a tangent that happenstance is incidentally contacting the surface of such plane of rotation, but is matched to the plane that we have in mind. In the case of a two dimension tangent computation, we'd likely have 2 possible solutions for such plane, and thus we have a bit of measured control over potential solutions to be yielded here. Once computing the new angle of r(x'',y'') I'd call theta' in the rotated coordinate axis, we can reconvert the tangent coordinates from the rotated coordinate system back into our original coordinate system, and voila we have a tangent vector that is situated to a given rotational plane. Here's a bit of python code expressing this trigonometric solution. You'd need to have numpy and python 2.6 installed on your system for this
So basically under a twice rotated coordinate system, we match for the angle theta on the xy plane to that of r, and then rotate to the x'z' plane to match the angle phi for coordinates x'',y'', z'' . This in turn should lead us to a vector whose coordinate is (x'', 0, 0), we can then simple compute on a given plane the orthogonal by computing the new direction of r at 90 degrees which should leave a component (0,y'',0) and then twice rotate back into our original coordinate system.
If you wanted to change the respective rotational plane you could rotate the coordinate plane from here on the y''z'' plane in any given orientation and then use the same process (90, or -90 degree) computation for the new vector r in the x''', y''', z''' coordinate system, and then reverse the process for coordinate transformations back into x, y, z. Thus this method provides a solution method for defining our given rotational plane and computing tangents on such a plane.
def unitnorm(r2): v = [] for x in r2: v.append([numpy.linalg.norm(x)]) v = array(v) return r2/v def tangentfromr2(r2): def orthogonalangle(x,y): return math.pi/2 + math.atan(y/x) def findtancoords(rxpyp,oalpha): return [rxpyp*math.cos(oalpha), rxpyp*math.sin(oalpha)] def findphi(rxy,z): return math.atan(z/rxy) def findrxy(x,y): return (x**2+y**2)**.5 def findrxyz(x,y,z): return (x**2+y**2+z**2)**.5 def rotationphi(phi): m = [(math.cos(phi),math.sin(phi)), (-math.sin(phi),math.cos(phi))] return numpy.array(m) def revrotationphi(phi): m = [(math.cos(phi),-math.sin(phi)), (math.sin(phi),math.cos(phi))] return numpy.array(m) def rotatecoords(x,z,R): xzcrd = [x,z] XZ = numpy.array(xzcrd) rXZ = numpy.dot(R,XZ) return rXZ
So basically under a twice rotated coordinate system, we match for the angle theta on the xy plane to that of r, and then rotate to the x'z' plane to match the angle phi for coordinates x'',y'', z'' . This in turn should lead us to a vector whose coordinate is (x'', 0, 0), we can then simple compute on a given plane the orthogonal by computing the new direction of r at 90 degrees which should leave a component (0,y'',0) and then twice rotate back into our original coordinate system.
If you wanted to change the respective rotational plane you could rotate the coordinate plane from here on the y''z'' plane in any given orientation and then use the same process (90, or -90 degree) computation for the new vector r in the x''', y''', z''' coordinate system, and then reverse the process for coordinate transformations back into x, y, z. Thus this method provides a solution method for defining our given rotational plane and computing tangents on such a plane.
No comments:
Post a Comment