|
"Roger Stafford" wrote in message <iu0979$ah$1@newscl01ah.mathworks.com>...
> "Armen" wrote in message <itvnh1$323$1@newscl01ah.mathworks.com>...
> > ..... I've set up the code you posted and it runs, but I'm encountering a different problem. As a check I've plugged in the vectors B and C, expecting returns of (bx,0,0) and (cx,cy,0), but instead it's just returning the original vectors I put in.
> - - - - - - - - - -
> I ran the test below and the results look correct to me, Armen. The quantities TA, TB, and TC have the transformed coordinates of points A, B, and C. Note that TA is at the new origin with all zeros, TB has only one non-zero component, and TC has only two, as should be the case.
>
> Notice that the first component of TB will not be bx = B(1). It must be the norm of the vector B-A, that is, the distance between A and B because you wanted A to be relocated at the new origin and the axes rotated so that B-A points along the new x-axis. A similar statement holds for TC - it is not [C(1),C(2),0]. It has also undergone a rotation and translation.
>
> The general formula
>
> TP = [dot(P-A,v1),dot(P-A,v2),dot(P-A,v3)]
>
> gives you the transform of any arbitrary point P = [x,y,z].
>
> You can test that the set v1,v2,v3 is orthonormal by seeing that
>
> [v1;v2;v3]*[v1;v2;v3]'
>
> produces the identity matrix (except for round off errors.)
>
> % The code
> clear
> format long
>
> % Choose three random points, A, B, C
> A = randn(1,3), B = randn(1,3), C = randn(1,3)
>
> % Compute the three new axes
> v1 = B-A; v1 = v1/norm(v1);
> v3 = cross(v1,C-A); v3 = v3/norm(v3);
> v2 = cross(v3,v1); % v2 is already a unit vector
>
> % Get the transforms of A, B, and C
> P = A;
> TA = [dot(P-A,v1),dot(P-A,v2),dot(P-A,v3)]
> P = B;
> TB = [dot(P-A,v1),dot(P-A,v2),dot(P-A,v3)]
> P = C;
> TC = [dot(P-A,v1),dot(P-A,v2),dot(P-A,v3)]
>
> % Results
> A = 0.63940564208852 0.87421289486361 1.75240173032956
> B = -0.32005082643214 -0.13741380814487 0.61576962808672
> C = 0.97789406984520 -1.11534771220514 -0.55002144880449
>
> TA = 0 0 0
> TB = 1.79885459030876 0 0.00000000000000
> TC = 2.39315386990053 1.90968397273444 -0.00000000000000
>
> Roger Stafford
Aha! I see what I did wrong - to test I was simply calling on the original points instead of newly-defined ones, of course that would simply map it back to the original coordinate space. Thanks again for your help and patience.
am
|