Jump to content
Gen. MERICA

Random position in rotated ellipse

Recommended Posts

I am having difficulty creating random positions inside of an ellipse.

As for now I have a (what I think is funny) work around by just doing a circle, and then checking the inArea command for the ellipse.

 

But does anyone know a quick equation to return a position inside of a rotated ellipse?

Tried searching around but I must be missing a search term or something.

Thanks

Share this post


Link to post
Share on other sites

I'm sure I've posted something similar in the forums before but I'm damned if I can find it. So..

//Create random elliptical marker
_mrk = createMarker [ "myEllipticalMarker", getPos player ];
_mrk setMarkerShape "ELLIPSE";
_mrk setMarkerSize [ ( random 100 ) + 75, ( random 25 ) + 25 ];
_mrk setMarkerDir random 360;
_mrk setMarkerBrush "Solid";
_mrk setMarkerColor "ColorBlack";
_mrk setMarkerAlpha 1;

//Function to get random position in elliptical marker
TAG_fnc_randomMarkerPos = {
	params[ "_mrk" ];
	
	_pos = getMarkerPos _mrk;
	markerSize _mrk params[ "_axisA", "_axisB" ];
	_dir = markerDir _mrk;
	
	_rndDir = random 360;
	_rndX = cos _rndDir * ( random _axisA );
	_rndY = sin _rndDir * ( random _axisB );
	
	_rndPos = [ [ _rndX, _rndY, 0 ], -_dir ] call BIS_fnc_rotateVector2D;
	
	_rndPos vectorAdd _pos
};

//Create 1000 test positions
for "_i" from 1 to 1000 do {
	_position = [ _mrk ] call TAG_fnc_randomMarkerPos;
	
	_rndMrk = createMarker [ format[ "test_%1", _i ], _position ];
	_rndMrk setMarkerShape "ICON";
	_rndMrk setMarkerType "hd_dot";
	_rndMrk setMarkerDir 0;
	_rndMrk setMarkerColor "ColorRed";
	_rndMrk setMarkerAlpha 1;
	_rndMrk setMarkerText "";
	
};

 

Share this post


Link to post
Share on other sites
1 hour ago, killzone_kid said:

Or you can use BIS_fnc_randomPosTrigger

 

Would inArea be a better option as opposed to the function or not?

Share this post


Link to post
Share on other sites
37 minutes ago, beno_83au said:

 

Would inArea be a better option as opposed to the function or not?


I dunno, it is like asking which command is better getPos or saveVar?

  • Like 2

Share this post


Link to post
Share on other sites

Ahhh yep, sorry, not sure where i was going with that one. 

  • Like 1

Share this post


Link to post
Share on other sites
6 hours ago, killzone_kid said:

Or you can use BIS_fnc_randomPosTrigger

 

Worth noting that this function doesn't produce uniformly distributed points when used on an ellipse. See 1000 plotted point with both BIS function and CBA function on identical circles here:

8oYAAL9.jpg

 

Link to current version of the CBA function

 

  • Like 1

Share this post


Link to post
Share on other sites
35 minutes ago, silentspike said:

 

Worth noting that this function doesn't produce uniformly distributed points when used on an ellipse. See 1000 plotted point with both BIS function and CBA function on identical circles here:

 

Link to current version of the CBA function

 

sqrt to the face!

 

Cheers

  • Like 2

Share this post


Link to post
Share on other sites

Both of these methods work perfectly, glad to see that people have these on stand by. They should really bundle some of the Take on helicopters functions into the default scripting area, I never check the functions outside of the Arma 3 search.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×