From: Roger Stafford on
"Els " <y.e.t.reeuwijk(a)student.utwente.nl> wrote in message <hud5md$sg3$1(a)fred.mathworks.com>...
> Dear Roger,
>
> Thanks for your complete response, very clear.
>
> P1 and P2 are no points on a cylinder, they are random points in space. The R1 and R2 are tangent points on the surface of the cylinder. So there will come a straight line from P1 to R1, then a geodesic over the surface of the cylinder from R1 to R2 and then again a straight line from R2 to P2. Resulting in the shortest path from P1 to P2.
>
> To get this, you have to make some assumptions, in the article I got from my Professor, was stated that the 4 points should be assumed to be in one plane.
>
> You stated that it was easy to show the above, did you mean my code, or your principle?
>
> Best wishes, Els
- - - - - - - - -
If R1 and R2 are points on the cylinder connected by a geodesic curve on the cylinder, and if P1R1 and P2R2 are lines pointing out along the two geodesic tangent directions at R1 and R2, respectively, then no, the two lines P1R1 and P2R2 cannot be assumed to lie in a common plane. Go to the extreme of a helix that has wrapped halfway around the cylinder and you can easily see that this would be impossible.

In answer to your question, I was stating that, given the principle that a geodesic curve's normal direction should always be parallel to the surface normal at every point, then the geodesic on a cylinder must be a helix. That is comparatively easy to show. I confess I didn't study your code carefully because the initial assumption of a common plane was apparently false.

To show that the geodesic must be a helix, do the following. Cartesian coordinates, r, t, and z (where t is short for theta) are related to cartesian coordinates by:

x = r*cos(t)
y = r*sin(t)
z = z

Letting s be the arc length along a geodesic, we have

ds = sqrt(dx^2 + dy^2 + dz^2) = sqrt((dx/dz)^2+(dy/dz)^2+1)*dz =
sqrt(r^2*(dt/dz)^2+1)*dz

Therefore the unit tangent is

[dx/ds , dy/ds , dz/ds] = [dx/dz , dy/dz , 1]*dz/ds =
[dx/dz , dy/dz , 1]*/sqrt(r^2*(dt/dz)^2+1) =
[-r*sin(t)*dt/dz , r*cos(t)*dt/dz , 1]/sqrt(r^2*(dt/dz)^2+1)

The geodesic normal is the derivative with respect to s of this unit tangent vector, and it must always be parallel to the surface normal which is [cost) , sin(t) , 0]. The derivative of the third component of the unit tangent will have a factor of d(dt/dz)/dz and since this component is zero in the surface normal, this second derivative must also be zero. That shows that dt/dz is a constant, and t is therefore a linear function of z. Hence the geodesic must be a helix.

Roger Stafford
From: Els on
Dear Roger,

The assumption of the fact that P1,P2,R1 and R2 are in one plane is correct, because is is about muscle wrapping, and the muscles do not wrap around the whole cylinder, but only have real small part arc length on the cylinder its self. I tried to understand your explanation further, but I must admit, that it is too difficult for me. The dx, dy, dz....are that the distances between R1 and R2? But I do not have R1 and R2, I want to calculate them. The only distance I know on forehand is the distance between P1 and P2, and the position and direction of the axis of the cylinder.

Hope I do not frustrate you, because I do appriciate your help very much. So thanks again a lot.

Best Wishes,

Els
From: Roger Stafford on
"Els " <y.e.t.reeuwijk(a)student.utwente.nl> wrote in message <hue8rb$80i$1(a)fred.mathworks.com>...
> Dear Roger,
>
> The assumption of the fact that P1,P2,R1 and R2 are in one plane is correct, because is is about muscle wrapping, and the muscles do not wrap around the whole cylinder, but only have real small part arc length on the cylinder its self. I tried to understand your explanation further, but I must admit, that it is too difficult for me. The dx, dy, dz....are that the distances between R1 and R2? But I do not have R1 and R2, I want to calculate them. The only distance I know on forehand is the distance between P1 and P2, and the position and direction of the axis of the cylinder.
>
> Hope I do not frustrate you, because I do appriciate your help very much. So thanks again a lot.
>
> Best Wishes,
>
> Els

No, I must firmly disagree with you. Even with a very small travel along a helix, the two lines R1P1 and R2P2 will not be coplanar. I only asked you to envision things halfway around because the statement should be glaringly obvious in that case. If you doubt this, try plugging some numbers into those formulae I gave you for a much smaller separation and check if the four points are coplanar. Four points, [x1,y1,z1], [x2,y2,z2], [x3,y3,z3], [x4,y4,z4], are coplanar if and only if the determinant

det([x1,x2,x3,x4;y1,y2,y3,y4;z1,z2,z3,z4;1,1,1,1])

is equal to zero.

However, your intuition ought to tell you that if the points are not colinear when the rotation is half way around the cylinder, that situation is not likely to suddenly clear up even if they are only part way around the cylinder. Actually they can't be coplanar unless P1 and P2 are the same points, or else the angle around the helix is some multiple of 2*pi (360 degrees).

Roger Stafford
From: Els on
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 ]
-------------------------
From: Roger Stafford on
"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