How to do this?
#1



Suppose 'O' is a center of a circle.
I want to create random objects, more clearly, I want to create random fire inside of the circle.
But how I can do it?
Reply
#2

Код:
new Float:centerX = 0.0;//center of the circle
new Float:centerY = 0.0;//center of the circle

new Float:radius = 3.0;//radius of the circle
new Float:random = frandom(0, 6.28);

new Float: px = centerX/2+floatcos(random,degrees)*radius;
new Float: py = centerY/2+floatsin(random,degrees)*radius;
	    
printf("x%f y%f",px,py);
Код:
Float:frandom(Float:max, Float:min = 0.0, dp = 4)//made by ******
{
    new Float:mul = floatpower(10.0, dp),

    imin = floatround(min * mul),
    imax = floatround(max * mul);
    return float(random(imax - imin) + imin) / mul;
}
Reply
#3

What is 6.28 in this line?
Код:
new Float:random = frandom(0, 6.28);
Reply
#4

That's 2 pi (pi = 3.141592654), 2 pi radians equal 360 degrees. However, since in the code above anglemode in floatcos and floatsin is set to degrees, "random" should be values between 0-360, not in radians.
Reply
#5

This code isn't working for me :/ it creates object outside of the circle...

if the center is 2814.9570,1313.2760,10.7500
and it's X Y is 2814.9570,1313.2760 then

Код:
Float:frandom(Float:max, Float:min = 0.0, dp = 4)//made by ******
{
    new Float:mul = floatpower(10.0, dp),

    imin = floatround(min * mul),
    imax = floatround(max * mul);
    return float(random(imax - imin) + imin) / mul;
}

COMMAND:fireup(playerid,params[]){
	new Float:centerX = 2814.9570;//center of the circle
	new Float:centerY = 1313.2760;//center of the circle

	new Float:radius = 3.0;//radius of the circle
	for(new i=0;i<8;i++){
		new Float:rrandom = frandom(0, 6.28);
		new Float: px = centerX/2+floatcos(rrandom,degrees)*radius;
		new Float: py = centerY/2+floatsin(rrandom,degrees)*radius;
		CreateObject(18688, px,py, 10.7500,0,0,0,300.0);
		printf("%f,%f",px,py);
	}
	//2814.9570,1313.2760,10.7500
	return 1;
}
and results:
Код:
1408.816772,658.124267
1406.247192,655.061950
1405.515258,657.019592
1408.596923,658.296081
1409.357910,657.322021
1406.039794,655.248657
1409.434814,657.053833
1407.825805,654.668395
Reply
#6

you can check my older thread maybe it helps

https://sampforum.blast.hk/showthread.php?tid=657613
Reply
#7

Quote:
Originally Posted by akib
Посмотреть сообщение
This code isn't working for me :/ it creates object outside of the circle...

if the center is 2814.9570,1313.2760,10.7500
and it's X Y is 2814.9570,1313.2760 then

Код:
Float:frandom(Float:max, Float:min = 0.0, dp = 4)//made by ******
{
    new Float:mul = floatpower(10.0, dp),

    imin = floatround(min * mul),
    imax = floatround(max * mul);
    return float(random(imax - imin) + imin) / mul;
}

COMMAND:fireup(playerid,params[]){
	new Float:centerX = 2814.9570;//center of the circle
	new Float:centerY = 1313.2760;//center of the circle

	new Float:radius = 3.0;//radius of the circle
	for(new i=0;i<8;i++){
		new Float:rrandom = frandom(0, 6.28);
		new Float: px = centerX/2+floatcos(rrandom,degrees)*radius;
		new Float: py = centerY/2+floatsin(rrandom,degrees)*radius;
		CreateObject(18688, px,py, 10.7500,0,0,0,300.0);
		printf("%f,%f",px,py);
	}
	//2814.9570,1313.2760,10.7500
	return 1;
}
and results:
Код:
1408.816772,658.124267
1406.247192,655.061950
1405.515258,657.019592
1408.596923,658.296081
1409.357910,657.322021
1406.039794,655.248657
1409.434814,657.053833
1407.825805,654.668395
Like niCe said, those angle calculations are in degrees, so instead of 6.28 you should use 360.0, otherwise the objects will only get spread between 0° and 6.28°.

Oh and remove the /2 from centerX and centerY, it's not neccessary. This already explains why the results are only half of your original coords.
Reply
#8

Thanks, it's working now. <3
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)