Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #171762
| From | John Forkosh <forkosh@panix.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: random points near central point |
| Date | 2023-08-07 13:11 +0000 |
| Organization | PANIX Public Access Internet and UNIX, NYC |
| Message-ID | <uaqqi0$ijf$1@reader2.panix.com> (permalink) |
| References | <eb9e82fb-265b-42a7-a245-1943e5b3b5aan@googlegroups.com> <ual9ur$t6d$1@reader2.panix.com> <89aaec9e-04e9-4b20-8bdc-7e0db8fca358n@googlegroups.com> |
fir <profesor.fir@gmail.com> wrote:
> John Forkosh wrote(a):
>> fir <profes...@gmail.com> wrote:
>> > i need to set asteroids in game (about 100 or 200) but not in square
>> > area with two rands one for x and second for y but need it to
>> > be sphericel symetric around central point and in more density near it
>> > and less desity with bigger radius until some radius when it is zero
>> >
>> > something like
>> > SetRandomPointSphericalSymetricAndFadingWithDistance(
>> > float x, float y, float r1, float r2);
>> > this r1 is radius of circle below which density is max and r2 is radius
>> > where above density is zero - in beetweem r1 and r2 density should
>> > be from max (at r1) to zero at r2
>> > how to do that?
>>
>> Haven't read the followups. You mean something like...
>> https://www.deviantart.com/eigenheit22/art/Starfield-v1-860092004
>> ...without the animation? That's done in x,y (and z). And you can then
>> just calculate r=sqrt(x*x+y*y) and discard the ones you don't like.
>
> possibly - now i think you just can imagine field of discarding
> (from 0.0 to 1.0 chance of discarding in given point) then just
> calculate chnce of discarding in that point according to a field
> and use it
>
> this is a bit wasteful to count something than discard it but
> probably could be enough ok
You said 100-200 asteroids, so "wasteful" is hardly a concern.
But if you're concerned anyway, suppose you wanted asteroids
at radius r1 <= r <= r2 (you wanted "max density" at r<=r1,
whereas this will give 0 at r<r1 and r>r2; your exercise is to
figure out the necessary modification). So go back to r,theta
polar coords and just do something along the following lines...
#include <stdlib.h>
#include <math.h>
void SetRandomPoint( double r1, double r2, double *x, double *y ) {
double r = r1 + (r2-r1)*drand48(), /* random r1<=r<r2 */
theta = 2.0*3.14159*drand48(); /* random 0<=theta<2pi */
*x = r*cos(theta); *y = r*sin(theta); /* return random x,y coords */
return; }
And the density will naturally decrease with increasing r.
No work required.
--
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
random points near central point fir <profesor.fir@gmail.com> - 2023-07-18 23:38 -0700
Re: random points near central point Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2023-07-19 01:49 -0700
Re: random points near central point fir <profesor.fir@gmail.com> - 2023-07-19 04:20 -0700
Re: random points near central point Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2023-07-19 01:59 -0700
Re: random points near central point Kaz Kylheku <864-117-4973@kylheku.com> - 2023-07-19 16:50 +0000
Re: random points near central point Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-07-19 20:23 +0100
Re: random points near central point fir <profesor.fir@gmail.com> - 2023-07-20 09:31 -0700
Re: random points near central point Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-07-20 20:42 +0100
Re: random points near central point fir <profesor.fir@gmail.com> - 2023-07-20 12:56 -0700
Re: random points near central point Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-07-20 20:59 +0100
Re: random points near central point David Brown <david.brown@hesbynett.no> - 2023-07-21 09:13 +0200
Re: random points near central point fir <profesor.fir@gmail.com> - 2023-07-21 05:55 -0700
Re: random points near central point Ed Prochak <edprochak@gmail.com> - 2023-07-22 12:24 -0700
Re: random points near central point fir <profesor.fir@gmail.com> - 2023-07-23 04:04 -0700
Re: random points near central point Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-07-23 14:53 +0100
Re: random points near central point fir <profesor.fir@gmail.com> - 2023-07-23 07:03 -0700
Re: random points near central point "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-07-23 12:30 -0700
Re: random points near central point Ed Prochak <edprochak@gmail.com> - 2023-07-30 21:48 -0700
Re: random points near central point fir <profesor.fir@gmail.com> - 2023-08-03 10:00 -0700
Re: random points near central point fir <profesor.fir@gmail.com> - 2023-07-20 13:20 -0700
Re: random points near central point "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-07-20 12:57 -0700
Re: random points near central point fir <profesor.fir@gmail.com> - 2023-07-20 13:18 -0700
Re: random points near central point "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-07-23 12:28 -0700
Re: random points near central point "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-07-20 12:56 -0700
Re: random points near central point Bonita Montero <Bonita.Montero@gmail.com> - 2023-08-03 19:17 +0200
Re: random points near central point fir <profesor.fir@gmail.com> - 2023-08-03 10:55 -0700
Re: random points near central point fir <profesor.fir@gmail.com> - 2023-08-03 11:04 -0700
Re: random points near central point Bonita Montero <Bonita.Montero@gmail.com> - 2023-08-04 17:22 +0200
Re: random points near central point fir <profesor.fir@gmail.com> - 2023-08-04 10:06 -0700
Re: random points near central point John Forkosh <forkosh@panix.com> - 2023-08-05 10:57 +0000
Re: random points near central point fir <profesor.fir@gmail.com> - 2023-08-05 05:41 -0700
Re: random points near central point John Forkosh <forkosh@panix.com> - 2023-08-07 13:11 +0000
Re: random points near central point fir <profesor.fir@gmail.com> - 2023-08-07 06:26 -0700
Re: random points near central point fir <profesor.fir@gmail.com> - 2023-08-07 06:33 -0700
Re: random points near central point "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-08-06 11:57 -0700
csiph-web