Example Code: Random Area Distribution: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
(Page creation)
 
m (Text replacement - " <nowiki>[</nowiki>" to " [<nowiki/>")
Line 43: Line 43:
  _angle = [[random]] 360;
  _angle = [[random]] 360;
  _distance = [[random]] _radius;
  _distance = [[random]] _radius;
  _offset = <nowiki>[</nowiki>[[sin]] _angle * _distance, [[cos]] _angle * _distance, 0];
  _offset = [<nowiki/>[[sin]] _angle * _distance, [[cos]] _angle * _distance, 0];
  _position = [_center, _offset] [[call]] [[BIS_fnc_vectorAdd]];
  _position = [_center, _offset] [[call]] [[BIS_fnc_vectorAdd]];
   
   
Line 49: Line 49:
  _angle = [[random]] 360;
  _angle = [[random]] 360;
  _distance = _radius * [[sqrt]] [[random]] 1;
  _distance = _radius * [[sqrt]] [[random]] 1;
  _offset = <nowiki>[</nowiki>[[sin]] _angle * _distance, [[cos]] _angle * _distance, 0];
  _offset = [<nowiki/>[[sin]] _angle * _distance, [[cos]] _angle * _distance, 0];
  _position = [_center, _offset] [[call]] [[BIS_fnc_vectorAdd]];
  _position = [_center, _offset] [[call]] [[BIS_fnc_vectorAdd]];


Line 65: Line 65:
  _angle = [[random]] 360;
  _angle = [[random]] 360;
  _distance = [[random]] _radius;
  _distance = [[random]] _radius;
  _offset = <nowiki>[</nowiki>[[sin]] _angle * _distance, [[cos]] _angle * _distance];
  _offset = [<nowiki/>[[sin]] _angle * _distance, [[cos]] _angle * _distance];
  _position = [(_center [[select]] 0) + (_offset [[select]] 0), (_center [[select]] 1) + (_offset [[select]] 1)];
  _position = [(_center [[select]] 0) + (_offset [[select]] 0), (_center [[select]] 1) + (_offset [[select]] 1)];
   
   
Line 71: Line 71:
  _angle = [[random]] 360;
  _angle = [[random]] 360;
  _distance = _radius * [[sqrt]] [[random]] 1;
  _distance = _radius * [[sqrt]] [[random]] 1;
  _offset = <nowiki>[</nowiki>[[sin]] _angle * _distance, [[cos]] _angle * _distance, 0];
  _offset = [<nowiki/>[[sin]] _angle * _distance, [[cos]] _angle * _distance, 0];
  _position = [(_center [[select]] 0) + (_offset [[select]] 0), (_center [[select]] 1) + (_offset [[select]] 1)];
  _position = [(_center [[select]] 0) + (_offset [[select]] 0), (_center [[select]] 1) + (_offset [[select]] 1)];


Line 85: Line 85:
  _angle = [[random]] 360
  _angle = [[random]] 360
  _distance = [[random]] _radius
  _distance = [[random]] _radius
  _offset = <nowiki>[</nowiki>[[sin]] _angle * _distance, [[cos]] _angle * _distance]
  _offset = [<nowiki/>[[sin]] _angle * _distance, [[cos]] _angle * _distance]
  _position = [(_center [[select]] 0) + (_offset [[select]] 0), (_center [[select]] 1) + (_offset [[select]] 1)]
  _position = [(_center [[select]] 0) + (_offset [[select]] 0), (_center [[select]] 1) + (_offset [[select]] 1)]
   
   
Line 91: Line 91:
  _angle = [[random]] 360
  _angle = [[random]] 360
  _distance = _radius * [[sqrt]] [[random]] 1
  _distance = _radius * [[sqrt]] [[random]] 1
  _offset = <nowiki>[</nowiki>[[sin]] _angle * _distance, [[cos]] _angle * _distance, 0]
  _offset = [<nowiki/>[[sin]] _angle * _distance, [[cos]] _angle * _distance, 0]
  _position = [(_center [[select]] 0) + (_offset [[select]] 0), (_center [[select]] 1) + (_offset [[select]] 1)]
  _position = [(_center [[select]] 0) + (_offset [[select]] 0), (_center [[select]] 1) + (_offset [[select]] 1)]




[[Category: Example Code]]
[[Category: Example Code]]

Revision as of 10:23, 19 March 2020

From left to right:
  1. random radius
  2. random position in a circle
  3. Gaussian normal distribution

Originally from Commy2's forum post, also fully translated on Dedmen's sqf.ovh post.


2

  • object getPos [distance, direction] has been introduced in Arma 3 logo black.png1.55
  • Gaussian random [min, mid, max] has been introduced in Arma 3 logo black.png1.55
private _center = getPosATL player;					// disc center definition
private _radius = 50;								// radius definition

// random radius
private _angle = random 360;						// angle definition (0..360)
private _distance = random _radius;					// distance from the center definition (0..radius)
private _position = _center getPos [_distance, _angle];

// random position
private _angle = random 360;						// angle definition (0..360)
private _randomSquareRoot = sqrt random 1;			// random square-root to obtain a non-linear 0..1 value
private _distance = _radius * _randomSquareRoot;	// distance from the center definition (0..radius)
private _position = _center getPos [_distance, _angle];

// Gaussian normal distribution
private _angleHalf = random 180;
private _randomGauss = random [-1, 0, 1];
private _distance = _radius * _randomGauss;
private _position = _center getPos [_distance, _angleHalf];


2

private ["_center", "_radius", "_angle", "_distance", "_offset", "_position"];	// private definitions
_center = getPosATL player;	// disc center definition
private _radius = 50;		// radius definition

// random radius
_angle = random 360;
_distance = random _radius;
_offset = [sin _angle * _distance, cos _angle * _distance, 0];
_position = [_center, _offset] call BIS_fnc_vectorAdd;

// random position
_angle = random 360;
_distance = _radius * sqrt random 1;
_offset = [sin _angle * _distance, cos _angle * _distance, 0];
_position = [_center, _offset] call BIS_fnc_vectorAdd;


-wrong parameter ("Arma") defined!-1.00 ofpr version.gif1.85

2

private ["_center", "_radius", "_angle", "_distance", "_offset", "_position"];	// private definitions
_center = getPos player;	// disc center definition - getPosASL can be used in Arma
private _radius = 50;		// radius definition

// random radius
_angle = random 360;
_distance = random _radius;
_offset = [sin _angle * _distance, cos _angle * _distance];
_position = [(_center select 0) + (_offset select 0), (_center select 1) + (_offset select 1)];

// random position
_angle = random 360;
_distance = _radius * sqrt random 1;
_offset = [sin _angle * _distance, cos _angle * _distance, 0];
_position = [(_center select 0) + (_offset select 0), (_center select 1) + (_offset select 1)];


2

This is an SQS syntax example.
private ["_center", "_radius", "_angle", "_distance", "_offset", "_position"]	// private definitions
_center = getPos player		// disc center definition
_radius = 50				// radius definition

// random radius
_angle = random 360
_distance = random _radius
_offset = [sin _angle * _distance, cos _angle * _distance]
_position = [(_center select 0) + (_offset select 0), (_center select 1) + (_offset select 1)]

// random position
_angle = random 360
_distance = _radius * sqrt random 1
_offset = [sin _angle * _distance, cos _angle * _distance, 0]
_position = [(_center select 0) + (_offset select 0), (_center select 1) + (_offset select 1)]