Difference between revisions of "MIST getRandPointInCircle"

From DCS World Wiki - Hoggitworld.com
 
 
(2 intermediate revisions by 2 users not shown)
Line 5: Line 5:
 
|vNum = Mist 2.0
 
|vNum = Mist 2.0
  
|desc= Returns a randomly generated vec2 coordinate within the specified radius around the center of vec 2 or vec3 point given. If the optional variable innerRadius is given the random point will be generated that has a minimum distance of innerRadius and a maximum distance of radius from the point.|
+
|desc= Returns a randomly generated vec2 coordinate within the specified radius around the center of vec 2 or vec3 point given. If the optional variable innerRadius is given the random point will be generated that has a minimum distance of innerRadius and a maximum distance of radius from the point.
 +
 
 +
The optional values maxA and minA can be used to limit the possible area of a circle that the random point is returned within. Think of a pizza slice or Pacman as the shape that can be returned. '''maxA and minA are defined in degrees'''. These values can be any number, however it is important to realize that they are used to generate a random point in a circle. maxA set to 540 for instance would simply result in a higher probability of the point returning in the right half of the circle compared to the left half.
 +
 
 +
maxA is optional. If not present then it assumes the shape is a circle.
 +
 
 +
minA is optional. If not present then the range will assume minA is 0 (North) to whatever maxA is set to if present.
  
 
|rtnType= vec2
 
|rtnType= vec2
Line 33: Line 39:
 
|optName1= innerRadius
 
|optName1= innerRadius
  
|optType2=  
+
|optType2= number
  
|optName2=  
+
|optName2= maxA
  
|optType3=  
+
|optType3= number
  
|optName3=  
+
|optName3= minA
  
 
|optType4=  
 
|optType4=  
Line 54: Line 60:
 
  radius = any positive number
 
  radius = any positive number
 
  innerRadius = any positive number less than radius
 
  innerRadius = any positive number less than radius
 +
maxA = A number in degrees with 0 being North
 +
minA = A number in degrees. Should be smaller than maxA value.
  
 
|rtnExamples= {{vec2}}
 
|rtnExamples= {{vec2}}
Line 66: Line 74:
 
end
 
end
 
</code>
 
</code>
|notes= Used within: [[groupToRandomZone]], [[groupRandomDistSelf]], [[groupToRandomPoint]]
+
 
 +
 
 +
The following will generate a point based off the heading of a unit so that the new point is offset up to 90 degrees from the current heading of the unit.
 +
 
 +
    local u = Unit.getByName('whatever')
 +
    local headingDeg = math.deg(mist.getHeading(u, true))
 +
    local newPoint = mist.getRandPointInCircle(u:getPoint(), 20000, 10000, headingDeg + 90, headingDeg - 90)
 +
 
 +
|notes= Used within: [[MIST_groupToRandomZone|groupToRandomZone]], [[MIST_groupRandomDistSelf|groupRandomDistSelf]], [[MIST_groupToRandomPoint|groupToRandomPoint]]
 
|funcs= {{ListOfMistGeneralPurposeFuncs}}
 
|funcs= {{ListOfMistGeneralPurposeFuncs}}
  
 
}}
 
}}
 
[[Category: MIST|getRandomPointInCircle]]
 
[[Category: MIST|getRandomPointInCircle]]

Latest revision as of 23:01, 3 June 2021


mist.getRandPointInCircle

Added with: Mist 2.0
Description
Returns a randomly generated vec2 coordinate within the specified radius around the center of vec 2 or vec3 point given. If the optional variable innerRadius is given the random point will be generated that has a minimum distance of innerRadius and a maximum distance of radius from the point.

The optional values maxA and minA can be used to limit the possible area of a circle that the random point is returned within. Think of a pizza slice or Pacman as the shape that can be returned. maxA and minA are defined in degrees. These values can be any number, however it is important to realize that they are used to generate a random point in a circle. maxA set to 540 for instance would simply result in a higher probability of the point returning in the right half of the circle compared to the left half.

maxA is optional. If not present then it assumes the shape is a circle.

minA is optional. If not present then the range will assume minA is 0 (North) to whatever maxA is set to if present.

Syntax
vec2 mist.getRandPointInCircle(table vec2/vec3 ,number radius , number innerRadius ,number maxA ,number minA )
Valid Input Values:
vec2/vec3 = valid vec2/3 table
radius = any positive number
innerRadius = any positive number less than radius
maxA = A number in degrees with 0 being North
minA = A number in degrees. Should be smaller than maxA value.
Return value:
vec2
Return example:
Template:Vec2
Usage Examples:
The following code will deploy a smoke marker randomly inside a zone.

do

local zone = trigger.misc.getZone('myZone')
local newPoint = mist.getRandPointInCircle(zone.point, zone.radius)

end


The following will generate a point based off the heading of a unit so that the new point is offset up to 90 degrees from the current heading of the unit.

   local u = Unit.getByName('whatever')
   local headingDeg = math.deg(mist.getHeading(u, true))
   local newPoint = mist.getRandPointInCircle(u:getPoint(), 20000, 10000, headingDeg + 90, headingDeg - 90)
Notes:
Used within: groupToRandomZone, groupRandomDistSelf, groupToRandomPoint
Related Functions
makeUnitTable, getRandPointInCircle, getRandomPointInZone, getRandomPointInPoly, isTerrainValid, terrainHeightDiff, getUnitsInZones, getUnitsInMovingZones, pointInPolygon, getUnitsInPolygon, getDeadMapObjsInZones, getDeadMapObjsInPolygonZone, getUnitsLOS, random, randomizeNumTable, getAvgPoint, getQFE, getWindBearingAndVel, getPathLength, getPathInSegments, getPointAtDistanceOnPath, projectPoint, getGroupsByAttribute, , getUnitsByAttribute, mapValue,

Scripting Engine

MIST Root Page