Path: csiph.com!news.swapon.de!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: Tim Rentsch
Newsgroups: comp.lang.c
Subject: Re: quick & easy random dir vector, how?
Date: Tue, 04 Jun 2019 10:00:54 -0700
Organization: A noiseless patient Spider
Lines: 63
Message-ID: <86pnntffp5.fsf@mailhub.linuxsc.com>
References: <8b69f6c2-5be5-4f24-9070-86dd24a42cd5@googlegroups.com> <20190601004024.f79363b8206f7b1d52198326@gmail.com> <_LPIE.36178$xY3.31763@fx01.iad> <8636krgnlh.fsf@mailhub.linuxsc.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="822064cc3cc2a6ececc8a34836f7fa7b"; logging-data="11032"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18YH3jfE3cQmlWqDZDeQ4+zThqcw7j7qww="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:+gFeLuLdiv4uittNnWajSxVarmA= sha1:zy0d1Jqh+YUE7StRUQ83kWdcF+Q=
Xref: csiph.com comp.lang.c:144413
Clifford Heath writes:
> On 3/6/19 5:00 pm, Tim Rentsch wrote:
>
>> Clifford Heath writes:
>>
>>> On 1/6/19 7:40 am, Anton Shepelev wrote:
>>>
>>>> fir:
>>>>
>>>>> sometimes you want random int, but sometimes you need
>>>>> random dir vector in 3d space (by random dir i mean
>>>>> randomly directed and of length 1.00)
>>>>>
>>>>> how to generate it to be generated quick (sometimes i may
>>>>> need to generate tons of them so quick is important) and
>>>>> easy?
>>>>
>>>> Consider an observer in the center of a sphere. A random
>>>> point lies at a random asimuth, so choose
>>>>
>>>> phi = Tau * [0,1] .
>>>>
>>>> The elevation xi is more difficult because the amount M of
>>>> points at a certain elevation is proportional to the
>>>> circumference at this height, i.e.
>>>>
>>>> M ~ Tau * cos xi ,
>>>>
>>>> and so should be the probability of choosing a certain xi:
>>>>
>>>> P(xi) = cos xi => xi = arccos [-1,1] .
>>>
>>> Can this be done more understandably using quaternions?
>>> I suspect it can.
>>
>> I don't think so. Quaternions are just a particular representation
>> for a rotation in 3-space, or a way of representing an orientation
>> in 3-space if one wants to think of them that way. Given a random
>> quaternion, it's easy to get a random direction vector out of it,
>> but similarly vice versa. The two problems are almost identical -
>> it's hard to imagine a solution for one being especially easier
>> to understand than solving the other more directly.
>
> I have so far failed to fully understand quaternions, but they
> represent a 4D space that folds into a 3D system without having
> the problems of "gimbal lock" that occurs in polar 3D systems.
>
> "Directly overhead" is 90 degrees elevation, but what is the
> azimuth? Quaternions never need to ask that question. But
> perhaps the present issue doesn't present that problem anyhow.
I don't fully understand quaternions either. To the extent that
I do understand them, my instinct tells me they aren't going to
be useful for this problem, mainly because they are tied to a
particular (orthonormal) coordinate system. The choice of
coordinate system introduces some bias (or so my instincts lead
me to believe), which puts us back where we started of having to
compensate for the bias. Only now I don't understand what the
bias is. :)
For better or worse, there are the fuzzy thoughts behind my
fuzzy understanding.