Prev: Growing matrix
Next: Loading a large dataset from a database-- java.lang.OutOfMemoryError: Java heap space
From: Els on 6 Jun 2010 13:29 "Roger Stafford" <ellieandrogerxyzzy(a)mindspring.com.invalid> wrote in message <hugjcb$23v$1(a)fred.mathworks.com>... > "Els " <y.e.t.reeuwijk(a)student.utwente.nl> wrote in message <hugb08$ns6$1(a)fred.mathworks.com>... > > Ok, and now I do have the two points on the surface. How do I calculate the distance between them? Because the problem is that my cylinder is rotated along a line, and that I can't use the calculation below. > > > > ------------------------ > > > > If P1 and P2 have rectangular coordinates (x1,y1,z1) and (x2,y2,z2), their cylindrical > > coordinates are (r*cos(t1),r*sin(t1),z1) and (r*cos(t2),r*sin(t2),z2), where t1 and t2 are in > > radians. If we now unroll the cylinder onto the plane x=r, P1 goes to Q1 and P2 goes to > > Q2. The rectangular coordinates of Q1 and Q2 are > > Q1=(r,r*t1,z1) > > Q2=(r,r*t2,z2) > > > > The distance d from P1 to P2, on the cylinder, is equal to the distance from Q1 to Q2, > > namely, > > > > d = sqrt[ (r*t1 - r*t2)^2 + (z1-z2)^2 ] > > ------------------------- > > Yes, that last formula is indeed the best way to calculate the kind of cylindrical "distance" you are seeking. It should however be modified a bit. Something like this: > > d = sqrt((r*(mod(t2-t1+pi,2*pi)-pi))^2+(z1-z2)^2) > > The unrolled cylinder has to be conceived as having at least two other unrolled copies rather than just the one extending from 0 to 2*pi*r, and you need to select the shortest straight line path between the copies of P1 and P2. The mod operation above does that. > > As for making use of this method, you first have to do a translation of some point on your axis line over to the origin and bring P1 and P2 along with it. Then you have to rotate this translated axis so as to lie along the z-axis, again rotating P1 and P2 along with it. I think you've had advice in the past about how to do this rotation. Next you convert the new P1 and P2 cartesian coordinates to cylindrical coordinates. Then finally you can use the above method. > > By the way, this method of unrolling a cylinder should be a powerful indicator that indeed the geodesics on circular cylinders are the helices (except of course when the angles are equal and they are straight lines, or when the z coordinates are equal and they are circles.) > > Roger Stafford Dear Roger, For my understanding, you are implying that I have to rotate and translate the axis of the cylinder. And do the same with points P1 and P2. Then I can calculate the cylindrical coordinates and use your formula. Concerning the ellipsoids, you gave me the following code to do the rotation: ------------------------------------- % Calculate necessary rotation data t = t/norm(t); % Make t a unit vector u = [1,0,0]; % Unit vector along the positive x-axis w = cross(u,t); % The axis of rotation cosa = dot(u,t); % Cosine of the angle of rotation sina = norm(w); % Sine of the angle of rotation w = w/sina; % Make w a unit vector v = cross(w,u); % Unit vector orthogonal to u and w % Proceed with the rotation transformation n = numel(x); % Number of points in surface p = [x(:),y(:),z(:)]; % Create n x 3 array of ellipsoid surface points u = repmat(u,n,1); % Match sizes of u, v, and w to that of p v = repmat(v,n,1); w = repmat(w,n,1); wp = cross(w,p,2); q = dot(p,w,2)*w + cosa*cross(wp,w,2) + sina*wp; % Rotate p xr = q(:,1); yr = q(:,2); zr = q(:,3); % Extract components xr = reshape(xr,size(x)); % These are the rotated coordinates yr = reshape(yr,size(x)); % in mesh format again zr = reshape(zr,size(x)); % Now plot the rotated surface surf(xr,yr,zr) --------------------------- But if I am correct, I have to rotate now over 3 axis, to get the axis of my cylinder on the origin. The translation is simple, but the rotation afterwards I still don't get in Matlab. As for the above code, t should be the vector from the origin to the point on the z-axis which corresponds with the length of the cylinder (t=[0 0 LengthCylinder]) and u should be [0,0,1], still my cylinder is pointed along the original (but translated) axis. Best Wishes, Els
First
|
Prev
|
Pages: 1 2 3 Prev: Growing matrix Next: Loading a large dataset from a database-- java.lang.OutOfMemoryError: Java heap space |