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


Groups > comp.lang.c > #170892 > unrolled thread

random points near central point

Started byfir <profesor.fir@gmail.com>
First post2023-07-18 23:38 -0700
Last post2023-08-06 11:57 -0700
Articles 15 on this page of 35 — 9 participants

Back to article view | Back to comp.lang.c


Contents

  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

Page 2 of 2 — ← Prev page 1 [2]


#170983

From"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>
Date2023-07-20 12:57 -0700
Message-ID<u9c3iv$2rpbs$2@dont-email.me>
In reply to#170973
On 7/20/2023 9:31 AM, fir wrote:
> środa, 19 lipca 2023 o 21:24:09 UTC+2 Ben Bacarisse napisał(a):
>> fir <profes...@gmail.com> writes:
>>
>>> i need tos et 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 densitu near it
>>> and less desity with bigger radius until some radius when it is zero
>> If you just pick a uniform angle and a uniform radius and plot those
>> points, the density of points near the origin will be higher. This is a
>> very simple method and might be suitable for a game.
> 
> uniform  radius? dont know what is that
> 
> generally i need whole pack of functions to set things arndomly but not just in rectangle whuich
> will be given by applaying rand to x and y
> this spherical group with decaying density with radius is one of that
> 
>>> something like
>>>
>>> SetRandomPointSphericalSymetricAndFadingWithDistance(
>>> float x, float y, float r1, float r2);
>> This suggests that I've not understood your opening paragraph, but I
>> offer the solution in case someone else might be interested.
>>> 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?

Random angles and random radii that are locked in the unit circle? 
Should be good enough?

[toc] | [prev] | [next] | [standalone]


#170989

Fromfir <profesor.fir@gmail.com>
Date2023-07-20 13:18 -0700
Message-ID<64228552-63a4-45b2-b332-b29d05967707n@googlegroups.com>
In reply to#170983
czwartek, 20 lipca 2023 o 21:57:33 UTC+2 Chris M. Thomasson napisał(a):
> On 7/20/2023 9:31 AM, fir wrote: 
> >>> how to do that?
> Random angles and random radii that are locked in the unit circle? 
> Should be good enough?

i dont know maybe randomize in circle of R2 then in some steps randomize in smaller circle until i reach R1 ?

there should be some easy methods i guess..hovevver im not sur if geting random in polar coordinates gives really random in 2d space...maybe its natorally more density near centre then?

[toc] | [prev] | [next] | [standalone]


#171180

From"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>
Date2023-07-23 12:28 -0700
Message-ID<u9jv0j$b0q1$1@dont-email.me>
In reply to#170989
On 7/20/2023 1:18 PM, fir wrote:
> czwartek, 20 lipca 2023 o 21:57:33 UTC+2 Chris M. Thomasson napisał(a):
>> On 7/20/2023 9:31 AM, fir wrote:
>>>>> how to do that?
>> Random angles and random radii that are locked in the unit circle?
>> Should be good enough?
> 
> i dont know maybe randomize in circle of R2 then in some steps randomize in smaller circle until i reach R1 ?
> 
> there should be some easy methods i guess..hovevver im not sur if geting random in polar coordinates gives really random in 2d space...maybe its natorally more density near centre then?


Create the random angles and random radii locked in a circle. Lets start 
small with a unit circle centered at origin {0, 0}. Just plot the 
points. Convert the polar form to rectangular, and plot the points 
during iteration. For each iteration create a random radius from 0...1 
and a random angle from 0...pi2:

vec2 r0_normal = { cos(random_angle), sin(random_angle) };

vec2 r0 = origin + r0_normal * random_radius;

plot(r0);

Should be okay enough?


[toc] | [prev] | [next] | [standalone]


#170982

From"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>
Date2023-07-20 12:56 -0700
Message-ID<u9c3h4$2rpbs$1@dont-email.me>
In reply to#170892
On 7/18/2023 11:38 PM, fir wrote:
> i need tos et 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 densitu 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?

Diffuse the points around the central point. This is an example however 
it has a bias in the corners of the rotated unit square:

http://fractallife247.com/fdla/

Click around.

[toc] | [prev] | [next] | [standalone]


#171573

FromBonita Montero <Bonita.Montero@gmail.com>
Date2023-08-03 19:17 +0200
Message-ID<uagne8$rfjo$1@dont-email.me>
In reply to#170892
Am 19.07.2023 um 08:38 schrieb fir:
> i need tos et 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 densitu 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?

In C++ I'd do that this way:

#include <random>
#include <cmath>

using namespace std;

double nearDistance( double d )
{
	thread_local double exp = 2.0;
	thread_local mt19937_64 mt;
	thread_local uniform_real_distribution<double> rnd1( 0.0, 1.0 );
	if( d < 0.0 ) [[unlikely]]
	{
		double beforeExp = exp;
		exp = -d;
		return beforeExp;
	}
	return pow( rnd1( mt ), exp ) * d;
}

This gives values from 0.0 to d which are more likely to be near
to 0.0 than with a linear exponent. The exponent can be changed
and should be > 1.0.

[toc] | [prev] | [next] | [standalone]


#171574

Fromfir <profesor.fir@gmail.com>
Date2023-08-03 10:55 -0700
Message-ID<8412502b-87b6-4ce2-933b-f2b8eea2b181n@googlegroups.com>
In reply to#171573
czwartek, 3 sierpnia 2023 o 19:17:11 UTC+2 Bonita Montero napisał(a):
> Am 19.07.2023 um 08:38 schrieb fir: 
> > i need tos et 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 densitu 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?
> In C++ I'd do that this way: 
> 
> #include <random> 
> #include <cmath> 
> 
> using namespace std; 
> 
> double nearDistance( double d ) 
> { 
> thread_local double exp = 2.0; 
> thread_local mt19937_64 mt; 
> thread_local uniform_real_distribution<double> rnd1( 0.0, 1.0 ); 
> if( d < 0.0 ) [[unlikely]] 
> { 
> double beforeExp = exp; 
> exp = -d; 
> return beforeExp; 
> } 
> return pow( rnd1( mt ), exp ) * d; 
> } 
> 
> This gives values from 0.0 to d which are more likely to be near 
> to 0.0 than with a linear exponent. The exponent can be changed 
> and should be > 1.0.

dont know what it is, howewer thinkong of what i wrote 
if 
x = rand2(0,a); gives 'rectangle' density

//rand2(a,b) gives random from a to b)

then there i should probably transform helf of the points (as rectangle is two triangles) into triangle
but how? should i maybe take x/a which is from 0 to 1 and take it as a probablility of 'flipping'
the value from right-up triangl;e to left-down?
 
int GiveRandomVauleWithLinearlyDecayingDensity(int A, int B)
{
x = rand2(A,B);
float flip_probability = 1.*(x-A)/(B-A);
if(chance(flip_probability))  x = A + (B - x);
}

this just flips the x values from more right area of A to B span based on how right vaule this is

chance would be a function returning tru with a chance of flip_probability

dont know but maybe this is what i need

[toc] | [prev] | [next] | [standalone]


#171576

Fromfir <profesor.fir@gmail.com>
Date2023-08-03 11:04 -0700
Message-ID<4d51816d-ed7a-4969-84e0-c0c23037e79fn@googlegroups.com>
In reply to#171574
czwartek, 3 sierpnia 2023 o 19:55:44 UTC+2 fir napisał(a):
> czwartek, 3 sierpnia 2023 o 19:17:11 UTC+2 Bonita Montero napisał(a): 
> > Am 19.07.2023 um 08:38 schrieb fir: 
> > > i need tos et 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 densitu 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? 
> > In C++ I'd do that this way: 
> > 
> > #include <random> 
> > #include <cmath> 
> > 
> > using namespace std; 
> > 
> > double nearDistance( double d ) 
> > { 
> > thread_local double exp = 2.0; 
> > thread_local mt19937_64 mt; 
> > thread_local uniform_real_distribution<double> rnd1( 0.0, 1.0 ); 
> > if( d < 0.0 ) [[unlikely]] 
> > { 
> > double beforeExp = exp; 
> > exp = -d; 
> > return beforeExp; 
> > } 
> > return pow( rnd1( mt ), exp ) * d; 
> > } 
> > 
> > This gives values from 0.0 to d which are more likely to be near 
> > to 0.0 than with a linear exponent. The exponent can be changed 
> > and should be > 1.0.
> dont know what it is, howewer thinkong of what i wrote 
> if 
> x = rand2(0,a); gives 'rectangle' density 
> 
> //rand2(a,b) gives random from a to b) 
> 
> then there i should probably transform helf of the points (as rectangle is two triangles) into triangle 
> but how? should i maybe take x/a which is from 0 to 1 and take it as a probablility of 'flipping' 
> the value from right-up triangl;e to left-down? 
> 
> int GiveRandomVauleWithLinearlyDecayingDensity(int A, int B) 
> { 
> x = rand2(A,B); 
> float flip_probability = 1.*(x-A)/(B-A); 
> if(chance(flip_probability)) x = A + (B - x); 
> } 
> 
> this just flips the x values from more right area of A to B span based on how right vaule this is 
> 
> chance would be a function returning tru with a chance of flip_probability 
> 
> dont know but maybe this is what i need

btw how thuis chance function code shoule be?

int chance(float p)
{
  return p>= float(rand()&0x7fff)/0x7fff;;
}

?

[toc] | [prev] | [next] | [standalone]


#171617

FromBonita Montero <Bonita.Montero@gmail.com>
Date2023-08-04 17:22 +0200
Message-ID<uaj538$1aocd$1@dont-email.me>
In reply to#171574
Am 03.08.2023 um 19:55 schrieb fir:

> dont know what it is, ...

Im taking a random double between 0.0 and 1.0, exponentiate it with
an exponent > 1.0, thereby having more small output values than high
and then I multiply that with the maximum value supplied. This makes
the desired distribution where lower values are more likely as you
increase the exponent.

[toc] | [prev] | [next] | [standalone]


#171623

Fromfir <profesor.fir@gmail.com>
Date2023-08-04 10:06 -0700
Message-ID<cfaf3956-bcd0-4752-9ff2-60f70cbd8cd4n@googlegroups.com>
In reply to#171617
piątek, 4 sierpnia 2023 o 17:22:30 UTC+2 Bonita Montero napisał(a):
> Am 03.08.2023 um 19:55 schrieb fir: 
> 
> > dont know what it is, ... 
> 
> Im taking a random double between 0.0 and 1.0, exponentiate it with 
> an exponent > 1.0, thereby having more small output values than high 
> and then I multiply that with the maximum value supplied. This makes 
> the desired distribution where lower values are more likely as you 
> increase the exponent.

probably should work but i wrote this laternative with fliping...

on the right side the probablility of flipping to left (like 0.8 to 0.2, or 0.9 to 0.1) is
rising to 100% where on left it is rising form 0% so this probably could turn "rectangle" distribution into triangle... but i dont need this code for hurry so now im not plan to test it - will test it when i will need it

[toc] | [prev] | [next] | [standalone]


#171672

FromJohn Forkosh <forkosh@panix.com>
Date2023-08-05 10:57 +0000
Message-ID<ual9ur$t6d$1@reader2.panix.com>
In reply to#170892
fir <profesor.fir@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.
-- 
John Forkosh  ( mailto:  j@f.com  where j=john and f=forkosh )

[toc] | [prev] | [next] | [standalone]


#171681

Fromfir <profesor.fir@gmail.com>
Date2023-08-05 05:41 -0700
Message-ID<89aaec9e-04e9-4b20-8bdc-7e0db8fca358n@googlegroups.com>
In reply to#171672
sobota, 5 sierpnia 2023 o 12:57:46 UTC+2 John Forkosh napisał(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

thsi is a bit wastefull to count something than discard it but probably could be enough ok

[toc] | [prev] | [next] | [standalone]


#171762

FromJohn Forkosh <forkosh@panix.com>
Date2023-08-07 13:11 +0000
Message-ID<uaqqi0$ijf$1@reader2.panix.com>
In reply to#171681
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 )

[toc] | [prev] | [next] | [standalone]


#171764

Fromfir <profesor.fir@gmail.com>
Date2023-08-07 06:26 -0700
Message-ID<75bc1057-8934-44af-911e-cacbbec60bc2n@googlegroups.com>
In reply to#171762
poniedziałek, 7 sierpnia 2023 o 15:13:37 UTC+2 John Forkosh napisał(a):
> fir <profes...@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.

i wanted max constand density say in radius 100 then linerally decaying say 
in radius from 300

it seems the rand only givesflat density, then probably proper way fould be to tranmsform/project this square cordinates into other shape as density is proportional to 'surface'if some transforms the surface stretching it or densing by some x,y -> x', y' then it will have les random density

but i dont remember how to do transformations ([probably they are normal functions of x,y into new x,y so some could be found)  but there is also thsi way with making fields of percentage of discarding

this function is handy to me but its also not any way critical i need it jsu to set things in agme liak asteroid fields, space flowers or something liek that (but dont hope it would be look god i only write games wth symbolic graphics, something like kinda roguelikes)

[toc] | [prev] | [next] | [standalone]


#171765

Fromfir <profesor.fir@gmail.com>
Date2023-08-07 06:33 -0700
Message-ID<ab2d57c0-80f1-4729-9fe5-253edb910af4n@googlegroups.com>
In reply to#171764
poniedziałek, 7 sierpnia 2023 o 15:26:44 UTC+2 fir napisał(a):
> poniedziałek, 7 sierpnia 2023 o 15:13:37 UTC+2 John Forkosh napisał(a): 
> > fir <profes...@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.
> i wanted max constand density say in radius 100 then linerally decaying say 
> in radius from 300 
> 
> it seems the rand only givesflat density, then probably proper way fould be to tranmsform/project this square cordinates into other shape as density is proportional to 'surface'if some transforms the surface stretching it or densing by some x,y -> x', y' then it will have les random density 
> 


this waht you say is in fact such trabsformation x,x->x',y' buts its kinda wrong 
becouse near radius zero it has no limited densityand in radius 0.1 you got 10 percent
of all asteroids which simply might be to high..so i gusee there is soem another transformation which coudl be found better..though still its probably a bit harder to write it nly by transformation without discarding


> but i dont remember how to do transformations ([probably they are normal functions of x,y into new x,y so some could be found) but there is also thsi way with making fields of percentage of discarding 
> 
> this function is handy to me but its also not any way critical i need it jsu to set things in agme liak asteroid fields, space flowers or something liek that (but dont hope it would be look god i only write games wth symbolic graphics, something like kinda roguelikes)

[toc] | [prev] | [next] | [standalone]


#171738

From"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>
Date2023-08-06 11:57 -0700
Message-ID<uaoqf4$2ea19$2@dont-email.me>
In reply to#170892
On 7/18/2023 11:38 PM, fir wrote:
> i need tos et 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 densitu 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?

Fwiw, check out this older simulation I made around 9 years ago:

https://youtu.be/-EaHLaZbMFs

It tries to diffuse itself...

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

Back to top | Article view | comp.lang.c


csiph-web