Path: news.mathworks.com!not-for-mail From: <HIDDEN> Newsgroups: comp.soft-sys.matlab Subject: Re: Defining a Coordinate System Date: Thu, 23 Jun 2011 20:55:05 +0000 (UTC) Organization: The MathWorks, Inc. Lines: 49 Message-ID: <iu0979$ah$1@newscl01ah.mathworks.com> References: <itt2rk$bv7$1@newscl01ah.mathworks.com> <itt5t5$l3n$1@newscl01ah.mathworks.com> <itvnh1$323$1@newscl01ah.mathworks.com> Reply-To: <HIDDEN> NNTP-Posting-Host: www-04-blr.mathworks.com Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: newscl01ah.mathworks.com 1308862505 337 172.30.248.35 (23 Jun 2011 20:55:05 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Thu, 23 Jun 2011 20:55:05 +0000 (UTC) X-Newsreader: MATLAB Central Newsreader 1187260 Xref: news.mathworks.com comp.soft-sys.matlab:733476 "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