Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!news1.google.com!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post01.iad.highwinds-media.com!newsfe08.iad.POSTED!33b9410e!not-for-mail
From: Doug Schwarz <see@sig.for.address.edu>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.9.2.15) Gecko/20110303 Lightning/1.0b2 Thunderbird/3.1.9
MIME-Version: 1.0
Newsgroups: comp.soft-sys.matlab
Subject: Re: Rotate 3D object to align with x-y plane
References: <ip7abl$p2g$1@fred.mathworks.com>
In-Reply-To: <ip7abl$p2g$1@fred.mathworks.com>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 32
Message-ID: <YMGtp.35826$J36.32204@newsfe08.iad>
X-Complaints-To: abuse-news@frontiernet.net
NNTP-Posting-Date: Tue, 26 Apr 2011 21:27:20 UTC
Organization: Frontier
Date: Tue, 26 Apr 2011 17:27:20 -0400
Xref: news.mathworks.com comp.soft-sys.matlab:723981

On 4/26/2011 4:36 PM, Greg wrote:
> Hi - I realize this is an old thread but I have a perhaps more explicit
> question. I have three points given in xyz coordinates. Obviously they
> are co-planar. Assume the origin is at the center of gravity of the
> three points. I wish to rotate the points such that the rotated points
> are in a plane parallel to the xy plane, ie z=0 plane. I seek a rotation
> operator that will apply this rotation to any set of points, and the
> inverse operator, to rotate back. I am not concerned with rotation about
> the z axis - ie, any rotation that puts the three points in a plane
> parallel to xy, and with the same distances between the pairs of points,
> will do.
>
> Thanks in advance -
> Greg


Principal Components Analysis.  Might be overkill, but it's easy to do.

xyz = rand(3,3);  % 3 random points, each row is x,y,z coords of a pt.
xyz = bsxfun(@minus,xyz,mean(xyz));  % make the mean = (0,0,0)

[c,xyz2] = princomp(xyz);  % xyz2 will be what you want.

xyz_hat = xyz2*c';  % xyz_hat = xyz

You'll need the Statistics Toolbox for princomp.  Let me know if you 
don't have it.

-- 
Doug Schwarz
dmschwarz&ieee,org
Make obvious changes to get real email address.