linearConversion: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "\| *((\[\[[a-zA-Z0-9_ |()]+\]\],? ?)+) * \}\}" to "|seealso= $1 }}")
(formatting)
Line 1: Line 1:
{{RV|type=command
{{RV|type=command


| arma3
|game1= arma3


|0.50
|version1= 0.50


|gr1= Math
|gr1= Math


| Converts given value from given "from" range to wanted "to" range. If clipping is set to [[true]], the resulting value is guaranteed to be within "to" range no matter what.<br><br> Say given range is 0 to 1 and wanted range is 0 to 100 (percent calculation). Given value 0.55 then will be <br><tt>[[linearConversion]] [0,1,0.55,0,100]; //55</tt><br> but if given value is 1.1<br><tt>[[linearConversion]] [0,1,1.1,0,100,[[false]]]; //110</tt><br> or if clipping is [[true]]  <br><tt>[[linearConversion]] [0,1,1.1,0,100,[[true]]]; //100</tt>
|descr= Converts given value from given "from" range to wanted "to" range. If clipping is set to [[true]], the resulting value is guaranteed to be within "to" range no matter what. {{Feature|arma3|Faster alternative to [[BIS_fnc_linearConversion]].}}


| '''linearConversion''' [minFrom, maxFrom, value, minTo, maxTo, clip]
|s1= '''linearConversion''' [minFrom, maxFrom, value, minTo, maxTo, clip]


|p1= [minFrom, maxFrom, value, minTo, maxTo, clip]: [[Array]]
|p1= minFrom: [[Number]] - start "from" range


|p2= minFrom: [[Number]] - start "from" range
|p2= maxFrom: [[Number]] - end "from" range


|p3= maxFrom: [[Number]] - end "from" range
|p3= value: [[Number]] - given value from "from" range


|p4= value: [[Number]] - given value from "from" range
|p4= minTo: [[Number]] - start "to" range


|p5= minTo: [[Number]] - start "to" range
|p5= maxTo: [[Number]] - end "to" range


|p6= maxTo: [[Number]] - end "to" range
|p6= clip (Optional, default [[false]]): [[Boolean]] - if [[true]], resulting value cannot leave "to" range


|p7= clip (Optional): [[Boolean]] - if [[true]], resulting value cannot leave "to" range. Default: [[false]]
|r1= [[Number]] - respectful value from "to" range


| [[Number]] - respectful value from "to" range
|x1= <code>{{cc|Say given range is 0 to 1 and wanted range is 0 to 100 (percent calculation). Given value 0.55 then will be 55}}
[[linearConversion]] [0,1,0.55,0,100];
{{cc|but if given value is 1.1 it will return 110}}
[[linearConversion]] [0,1,1.1,0,100,[[false]]];
{{cc|or if clipping is [[true]] it will return 100}}
[[linearConversion]] [0,1,1.1,0,100,[[true]]];</code>


|x1= <code>[[linearConversion]] [4, 8, 5, 0, 1, [[false]]<nowiki>]</nowiki>;</code>
|x2= <code>[[linearConversion]] [4, 8, 5, 0, 1, [[false]]<nowiki>]</nowiki>;</code>
|x2= Calculate days from 1/1/1970: <code>fnc_daysFromEpoc =  
 
|x3=<code>{{cc|Calculate days from 1/1/1970}}
fnc_daysFromEpoc =  
{
{
[[private]] _year = [[param]] [0];
[[private]] _year = [[param]] [0];
Line 41: Line 48:
[[hint]] [[str]] ([[date]] [[call]] fnc_daysFromEpoc);</code>
[[hint]] [[str]] ([[date]] [[call]] fnc_daysFromEpoc);</code>


|seealso= [[round]], [[floor]], [[ceil]], [[vectorLinearConversion]], [[bezierInterpolation]]
|seealso= [[round]] [[floor]] [[ceil]] [[vectorLinearConversion]] [[bezierInterpolation]]
}}
}}
<dl class='command_description'>
<!-- Note Section BEGIN -->
<dd class="notedate">Posted on Mar 29, 2014 - 09:39</dd>
<dt class="note">[[User:ffur2007slx2_5|ffur2007slx2_5]]<dd class="note">
(A3 0.50) It is recommended to use [[linearConversion]] instead of [[BIS_fnc_linearConversion]]:
<code>[[linearConversion]] [0,100,50,0,50,[[true]] ]; //same as [[0,100],50,[0,50]] [[call]] [[BIS_fnc_linearConversion]]</code>
As for clamp, true will disable new value out of its range while false won't:
<code>[[linearConversion]] [0,100,150,0,50,[[true]] ]; //return 50
[[linearConversion]] [0,100,150,0,50,[[false]] ]; //return 75
</code>
<!-- Note Section END -->
</dl>

Revision as of 12:00, 14 March 2021

Hover & click on the images for description

Description

Description:
Converts given value from given "from" range to wanted "to" range. If clipping is set to true, the resulting value is guaranteed to be within "to" range no matter what.
Arma 3
Faster alternative to BIS_fnc_linearConversion.
Groups:
Math

Syntax

Syntax:
linearConversion [minFrom, maxFrom, value, minTo, maxTo, clip]
Parameters:
minFrom: Number - start "from" range
maxFrom: Number - end "from" range
value: Number - given value from "from" range
minTo: Number - start "to" range
maxTo: Number - end "to" range
clip (Optional, default false): Boolean - if true, resulting value cannot leave "to" range
Return Value:
Number - respectful value from "to" range

Examples

Example 1:
// Say given range is 0 to 1 and wanted range is 0 to 100 (percent calculation). Given value 0.55 then will be 55 linearConversion [0,1,0.55,0,100]; // but if given value is 1.1 it will return 110 linearConversion [0,1,1.1,0,100,false]; // or if clipping is true it will return 100 linearConversion [0,1,1.1,0,100,true];
Example 2:
linearConversion [4, 8, 5, 0, 1, false];
Example 3:
// Calculate days from 1/1/1970 fnc_daysFromEpoc = { private _year = param [0]; private _days = 0; for "_i" from 1970 to _year - 1 do { _days = _days + round linearConversion [0, 1, dateToNumber [_i, 12, 31, 23, 59], 0, 365, false]; }; _days + linearConversion [0, 1, dateToNumber _this, 0, 365, false]; }; hint str (date call fnc_daysFromEpoc);

Additional Information

See also:
round floor ceil vectorLinearConversion bezierInterpolation

Notes

Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note