Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #144457

Re: Random direction using space partitioning?

Path csiph.com!xmission!news.snarked.org!news.linkpendium.com!news.linkpendium.com!panix!panix.com!forkosh
From John Forkosh <forkosh@panix.com>
Newsgroups comp.lang.c
Subject Re: Random direction using space partitioning?
Date Wed, 5 Jun 2019 04:36:07 +0000 (UTC)
Organization PANIX Public Access Internet and UNIX, NYC
Lines 64
Message-ID <qd7grn$qlb$1@reader2.panix.com> (permalink)
References <a7bdca34-9417-4351-a105-72004a37d6c6@googlegroups.com>
NNTP-Posting-Host panix3.panix.com
X-Trace reader2.panix.com 1559709367 27307 166.84.1.3 (5 Jun 2019 04:36:07 GMT)
X-Complaints-To abuse@panix.com
NNTP-Posting-Date Wed, 5 Jun 2019 04:36:07 +0000 (UTC)
User-Agent tin/1.6.2-20030910 ("Pabbay") (UNIX) (NetBSD/7.1.2 (i386))
Xref csiph.com comp.lang.c:144457

Show key headers only | View raw


luser droog <luser.droog@gmail.com> wrote:
> I had an idea about an algorithm for generating random
> unit vectors. Instead of mapping 2 or 3 random numbers
> to coordinates and then constraints and whatnot, ...
> what I we set up a 1D->3D mapping straight from a single
> number? In essence, the idea is to do something like a
> Hilbert Space Curve that does the same form of mapping,
> https://en.wikipedia.org/wiki/Hilbert_curve, but using
> a curve that is by definition constrained to the surface
> we want.
> 
> So, not to try to *do* it. My first thought is to sum
> up the six natural vectors along the three axes,
> 
>   ( bit_0 ? (1 0 0) : (-1 0 0) )
> + ( bit_1 ? (0 1 0) : (0 -1 0) )
> + ( bit_2 ? (0 0 1) : (0 0 -1) )
> + ( bit_3 ? ...
> 
> ... but then what? Some kind of weird, weighted things
> that I can't quite think of? This leads me to conclude
> that addition is not the right choice for the outer 
> operator.
> 
> So starting over, suppose we start with one vector and
> then compose rotations with smaller and smaller ranges
> of movement?
> 
>   ( bit_0 ? (1 0 0) : (-1 0 0) )
> * ( rotz( -90 + bit_1 * 180 ) )
> * ( rotx( -90 + bit_2 * 180 ) )
> * ( roty( -45 + bit_3 * 90 ) )
> * ( rotz( -45 + bit_4 * 90 ) )
> * ...
> 
> That seems better, but maybe by the second rotation we
> already don't want to be moving 180 degrees. And I still
> don't know how to extend it deeper into the space.
> 
> So for a third start, what if at each step we take two bits,
> the first determines whether to do the rotation or not, and
> the second determines the direction?
> 
>   ( bit_0 ? (1 0 0) : (-1 0 0) )
> * ( bit_1 ? rotz( -90 + bit_2 * 180 ) : identity )
> * ( bit_3 ? rotx( -90 + bit_4 * 180 ) : identity )
> 
> And that's as far as I got. Pretty rough, I know. 
> But space curves are cool, so it's gotta work right?

The idea that had occurred to me was as follows...
Place a sphere of any radius r (which can just be 1) at the origin.
Choose any great circle on that sphere, say the one in the xy-plane.
Its circumference is 2pi*r, so choose a random number c, 0<=c<2pi*r.
From any point on the chosen great circle, say x=r,y=0, move in
either direction (say positive-theta in the usual polar coords sense)
a distance c along the circumference. So that pretty clearly selects
a random point that solves the 2d problem.
   For 3d I'm not 100% sure about the following step. At the point
you selected above, construct the great circle that passes through
it and that's in a plane perpendicular to your original plane.
And now just do that random 0<=c<2pi*r thing again.
-- 
John Forkosh  ( mailto:  j@f.com  where j=john and f=forkosh )

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Random direction using space partitioning? luser droog <luser.droog@gmail.com> - 2019-06-04 19:35 -0700
  Re: Random direction using space partitioning? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-06-05 04:25 +0100
    Re: Random direction using space partitioning? Clifford Heath <no.spam@please.net> - 2019-06-05 13:30 +1000
  Re: Random direction using space partitioning? John Forkosh <forkosh@panix.com> - 2019-06-05 04:36 +0000
    Re: Random direction using space partitioning? Richard Damon <Richard@Damon-Family.org> - 2019-06-05 07:04 -0400
      Re: Random direction using space partitioning? "F. Russell" <frussell@random.info> - 2019-06-05 12:55 +0000

csiph-web