Re: Random directions
- From: ellieandrogerxyzzy@xxxxxxxxxxxxxxxxxxxxxx (Roger Stafford)
- Date: Tue, 01 Aug 2006 21:47:10 GMT
In article <ef3d2f4.-1@xxxxxxxxxxxxxxxxxxxxxxx>, "Jim Hnat"
<jhnat@xxxxxxxxx> wrote:
Dear Matlab users,-------------------------------------
I am trying to generate randomly oriented vectors, knowing the angle
between the random vector (RV) and a fixed vector (FV). Essentially
this gives me a cone about the FV.
Because the RV is a fixed angle from the FV, trying to use the rand()
funtion for one of the direction cosines of RV and solving for the
other two is not possible.
How might I go about generating these random vectors?
Thanks
-Jim
I have a few questions here. First, are you talking about three-element
vectors in three-dimensional space? I will assume here that that is the
case. Second, what sort of random distribution on the cone do you wish to
have? You probably want a uniform distribution of the angle transversely
around the cone over a 2*pi span, but what is the distribution to be along
the length of the cone? It can't be uniform since the length is
infinite. Also it can't be uniform over the surface area of the cone
since that is infinite too. Perhaps you are only interested in unit
length vectors? I will temporarily assume you want unit length random
vectors.
Let 'alpha' be the specified angle between RV and FV. Use matlab's
'null' function on the column vector FV to obtain two orthonormal column
vectors which are also orthogonal to FV. Call them p and q.
x = null(FV.'); p = x(:,1); q = x(:,2); % Two orthonormal vectors
beta = 2*pi*rand; % Random transverse angle
RV = FV/norm(FV)*cos(alpha)+(p*sin(beta)+q*cos(beta))*sin(alpha);
If you don't want to be restricted to unit length vectors, then generate
a random length, 'r', with whatever distribution you desire for the length
and do:
RV = r*RV;
If you want more than three-element vectors, that is a deeper problem.
I'll wait to hear from you about that.
Roger Stafford
.
- Follow-Ups:
- Re: Random directions
- From: Jim Hnat
- Re: Random directions
- References:
- Random directions
- From: Jim Hnat
- Random directions
- Prev by Date: Re: Check any figure exists
- Next by Date: Re: How can I assign black color only for NaNs in an image?
- Previous by thread: Random directions
- Next by thread: Re: Random directions
- Index(es):
Relevant Pages
|