Bounding box using Arma 3 scripting - sqf

This is a very basic question. I am new to Arma scripting and I'm trying to get a bounding box around a moving vehicle (named pickup_truck). How do I run this script?
http://www.armaholic.com/page.php?id=30924
say for eg: [pickup_truck] execVM "bb_object_1.sqf";
I was able to get this script ( http://killzonekid.com/arma-3-bounding-box-utility/ ) but the bounding box does not move along with the vehicle!

This is because vehicle's object bbox defined outside of "Draw3D" mission event handler. Once defined, this variable used in event handler code being unchanged.
Originally, KK's example not designed to show bounding box around moving vehicles.
If you want to show bounding box around moving vehicles, you must define bbox variable every event occur (inside event handler code). Then coordinates of bounding box points will be actual on each frame.
addMissionEventHandler function not allow to pass parameters inside handler code. Therefore KK's example used global variables bbox and bboxr to store bounding box info for acces to it from event handler code.
In such cases i prefer to use function BIS_fnc_addStackedEventHandler. This solution allow to pass parameters to event handler code (pickup_truck in code below).
Adopted KK's example:
[
"Whatever_EVH_Name_You_Want",
"onEachFrame",
{
private _veh = _this select 0;
private _bb = {
_bbx = [_this select 0 select 0, _this select 1 select 0];
_bby = [_this select 0 select 1, _this select 1 select 1];
_bbz = [_this select 0 select 2, _this select 1 select 2];
_arr = [];
0 = {
_y = _x;
0 = {
_z = _x;
0 = {
0 = _arr pushBack (_veh modelToWorld [_x,_y,_z]);
} count _bbx;
} count _bbz;
reverse _bbz;
} count _bby;
_arr pushBack (_arr select 0);
_arr pushBack (_arr select 1);
_arr
};
private _bbox = boundingBox _veh call _bb;
private _bboxr = boundingBoxReal _veh call _bb;
for "_i" from 0 to 7 step 2 do {
drawLine3D [
_bbox select _i,
_bbox select (_i + 2),
[0,0,1,1]
];
drawLine3D [
_bboxr select _i,
_bboxr select (_i + 2),
[0,1,0,1]
];
drawLine3D [
_bbox select (_i + 2),
_bbox select (_i + 3),
[0,0,1,1]
];
drawLine3D [
_bboxr select (_i + 2),
_bboxr select (_i + 3),
[0,1,0,1]
];
drawLine3D [
_bbox select (_i + 3),
_bbox select (_i + 1),
[0,0,1,1]
];
drawLine3D [
_bboxr select (_i + 3),
_bboxr select (_i + 1),
[0,1,0,1]
];
};
},
[pickup_truck]
] call BIS_fnc_addStackedEventHandler;

Related

I tried 'interp2' to measure the intensity of a line in octave but I have a method error, any suggestions

imshow(matrix(:,:,1))
%identify axes
[x y] = ginput(2);
% preallocate matrices
cog = zeros(size(matrix,3),1);
%cog
% loop start
for i = 1:size(maytrix,3)
I = matrix(:,:,i);
%n = ceil(norm([diff(x), diff(y)])); % A rough estimation of number of points
test = interp2(I, 2, linspace(x(1), x(2),n), linspace(y(1), y(2),n));
%test = round(test);
cog(i) = sum((1:length(test)).*test')/sum(test);
% loop end
end
scog = (cog - min(cog)) / (max(cog) - min(cog));
Here's a toy example to get you started.
% Create a 100x100x100 3D matrix with a certain pattern
% Smooth pattern:
matrix = [1 : 100] .' * [1 : 100];
matrix = matrix(:) * [1 : 100];
matrix = reshape( matrix, 100, 100, 100 );
% Alternatively, try a random matrix:
%matrix = randn(100,100,100);
Endpoints = randi( [1, 100], [3, 2] ); % Randomly get 2 3D points within matrix
Numpoints = max( abs( diff( Endpoints, 1, 2 ) ) ); % Choose width of widest dimension
% Create a line in 3D space (containing N points) going from one Endpoint to the other.
Linepoints = [ linspace( Endpoints(1, 1), Endpoints(1, 2), Numpoints );
linspace( Endpoints(2, 1), Endpoints(2, 2), Numpoints );
linspace( Endpoints(3, 1), Endpoints(3, 2), Numpoints ); ];
InterpolatedIntensities = interp3( 1:100, 1:100, 1:100, matrix, Linepoints(1, :), Linepoints(2, :), Linepoints(3, :) );
plot( InterpolatedIntensities );

Custom function used in a google sheets arrayfunction does not correctly update values

I'm new to google script. I am attempting to write a custom function that works with an arrayformula in google sheets. My implementation does not return the calculated value. My goal is to provide an updated calculation for data collected in a google form.
In a nutshell, I want to multiply a number by an amount based on a threshold based on type. e.g. the multiplier would only be applied for amount larger than a threshold.
Using the following google sheet
count, category, amount
2, a_type,=arrayformula(amount_calc(a2:a, b2:b, 25))
4, b_type,
7, a_type,
5, c_type,
I want to obtain the following result using an arrayformula
2, a_type, 0 //threshold: count>2
4, b_type, 75 //threshold: count>1
4, a_type, 50 //threshold: count>2
5, c_type, 25 //threshold: count>4
I've written the "amount_calc" function
function amount_calc(count, cat, multiplier) {
var amount=0
if(cat=="a_type" && count > 2) {
amount=(count - 2) * multiplier
} else if(cat=="a_type" && count <= 2) {
amount=0
}
if(cat=="b_type" && count > 1) {
amount=(count - 2) * multiplier
} else if(cat=="b_type" && count <= 1) {
amount=0
}
if(cat=="c_type" && count > 4) {
amount=(count - 4) * multiplier
} else if(cat=="b_type" && count <= 4) {
amount=0
}
return amount
}
The custom function as written produces the following result in the google sheet
2, a_type, 0
4, b_type, 0
4, a_type, 0
5, c_type, 0
From what I can the assignments in the if statements don't update the global variable "amount"
Alternately, I've unsuccessful tried accumulating the results in an amount array as follows
function amount_calc(count, cat, multiplier) {
var amount=[]
for (var i=0; i<count.length; i++ {
if(cat=="a_type" && num > 2) {
amount.push[i]((count - 2) * multiplier)
} else if(cat=="a_type" && count <= 2) {
amount.push[i](0)
}
if(cat=="b_type" && num > 1) {
amount.push[i]((count - 1) * multiplier)
} else if(cat=="b_type" && count <= 1 {
amount.push[i](0)
}
if(cat=="c_type" && num > 4) {
amount.push[i](count - 4) * multiplier)
} else if(cat=="b_type" && count <= 4 {
amount.push[i](0)
}
return amount
}
The result is a "Exceeded maximum execution time (line 0)" error.
Clearly I don't understand the function of the arrayformula. Am I mistaken to think it is iterating the function on each row? Why isn't the global variable 'amount' updated by the if statements. Any help or clarification would be appreciated.
Thanks, Kenny
Flow:
Create a Object map of types: {type: threshold}
Use Array.map to iterate rows and columns1
Sample script:
/**
* #param {number[][]} counts
* #param {string[][]} types
* #param {number} multiplier
*/
function amountcl(counts, types, multiplier) {
const typeCfg = { a_type: 2, b_type: 1, c_type: 4 };
return counts.map((row, i) =>
row.map((count, j) => {
let diff = count - typeCfg[types[i][j]];
return diff > 0 ? diff * multiplier : 0;
})
);
}

add 2 values together in an ssrs-expression

I'm looking to bring in my expression 2 values that I what to add together.
=Sum(iif(Fields!Leadsource.Value = "set1", 1, 0) and (Fields!Leadsource.Value = "set", 1, 0))
but is just coming back as 0 when the value should be 400 or so.
Can any one point me in the right direction?
I'm not sure how SSRS evaluates your expression
=Sum(iif(Fields!Leadsource.Value = "set1", 1, 0) and (Fields!Leadsource.Value = "set", 1, 0))
I think SUM(1 AND 0) and SUM(1 AND 1) both equal 1.
Your expression needs to be changed a little - though I'm not sure which you need.
=Sum(IIF(Fields!Leadsource.Value = "set1" OR Fields!Leadsource.Value = "set", 1, 0))
Otherwise if you want to count the two different criteria separately, use:
=Sum(IIF(Fields!Leadsource.Value = "set1", 1, 0) + (Fields!Leadsource.Value = "set", 1, 0))

Actionscript: Pseudo-Random Number creation with seeds

I am creating a function that returns a Perlin Noise Number in Flash.
For this function I must have a function that returns a random number from a static seed. Unfortunately the default Math.random in Actionscript can't do this..
I searched for a long time on the internet and I couldn't find a solution that fits my perlin-noise function.
I tried the following codes:
public static var seed:int = 602366;
public static function intNoise(x:int, y:int):Number {
var n:Number = seed * 16127 + (x + y * 57);
n = n % 602366;
seed = n | 0;
if (seed <= 0) seed = 1;
return (seed * 0.00000166) * 2 - 1;
}
This function does create a Random number, but the seed changes all the time so this doesn't work with perlin noise.
public static function intNoise(x:int, y:int):Number {
var n:Number = x + y * 57;
n = (n<<13) ^ n;
return ( 1 - ( (n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0);
}
I got this function from the Perlin Noise tutorial I followed: Perlin Noise, but it only seems to return 1.
How can I create a function that always returns the same Pseudo-Random number when called with the same seed?
I looked at the random number generator mentioned in the link and it looks like this:
function IntNoise(32-bit integer: x)
x = (x<<13) ^ x;
return ( 1.0 - ( (x * (x * x * 15731 + 789221) + 1376312589) & 7fffffff) / 1073741824.0);
end IntNoise function
I translated it thus:
package
{
import flash.display.*;
public class Main extends Sprite {
private var seeds:Array =
[ -1000, -999, -998, 7, 11, 13, 17, 999, 1000, 1001 ];
public function Main() {
for ( var i:int = 0; i < 10; i++ )
trace( intNoise( seeds[ i ] ) );
// Outputs: 1, 0, 0, -0.595146656036377, -0.1810436248779297,
// 0.8304634094238281, -0.9540863037109375, 0, 0, 1
}
// returns floating point numbers between -1.0 and 1.0
// returns 1 when x <= -1000 || x >= 1001 because b becomes 0
// otherwise performs nicely
public function
intNoise( x:Number ):Number {
x = ( uint( x << 13 ) ) ^ x;
var a:Number = ( x * x * x * 15731 + x * 789221 );
var b:Number = a & 0x7fffffff;
return 1.0 - b / 1073741824.0;
}
}
}

Code Golf: Movement in 3 Dimensions

Assuming a 3 dimensional irregular matrix where y = 1.5(x) and z = .5(y).
Further assuming an object starts at 0,0,0 and must move positively in at least two dimensions, and must move in all three dimensions (x+1, y+1, z-1 is okay, x+1, y+1, z=z is not). It may move any number of "spaces", but must move the same number in all directions.
The object is allowed to wraparound (x(max +1) = x(0)).
Move said object from its starting position to (0, max(y), .5(max(z))) For z, round up for fractions (end point in 4, 6, 3 matrix becomes 0, 6, 2)
Input is an Integer (X).
Output is the list of moves you would make (extra credit for showing the number of spaces you moved)
Sample Input/Output:
X = 4
Y = 6 //(4 * 1.5)
Z = 3 // 6 / 2
0, 0, 0 //Start
2, 5, 2 // (+2, -2, +2)
1, 2, 2 // (+4, +4, +4)
3, 4, 0 // (+2, +2, -2)
1, 6, 2 // (-2, +2, +2)
3, 3, 3 // (-3, -3, -3)
1, 5, 1 // (-2, +2, -2)
0, 6, 2 // (-1, +1, -1)
7 Moves.
Lua, 68 Characters
The long version below always solves the problem with one move by searching for the first all positive move that will solve problem.
x=...
y,z=x*3/2,x*3/4
a,b,c=0,y,math.ceil(z/2)
x,y,z=x+1,y+1,z+1
for i=1,math.huge do
if (x*i)%y==b and (x*i)%z==c then x=x*i break end
end
print("0,0,0\n0,"..b..","..c.."//+"..x..",+"..x..",+"..x.."\n1 move.")
Output for x = 12:
0,0,0
0,18,5//+455,+455,+455
1 move.
Output for x = 1000:
0,0,0
0,1500,375//+557424868,+557424868,+557424868
1 move.
Seems like the search could be replaced with some simple algebraic equation. But why stop there? Rules are easier to bend in golfing then doing the actual work.
So, assuming that there is always a single 1 move answer, and that I do not have to disclose the "number of spaces you moved", here is the 68 character golfed answer:
x=...print("0,0,0\n0,"..(x*3/2)..","..math.ceil(x*3/8).."\n1 move.")
Mathematica - Not Golfed
Just to see if we can get the ball rolling
... and trying to understand the problem ....
f[x_] := (
(* Init code *)
xmax = x;
ymax = 3 Round[xmax]/2;
zmax = Round[ymax]/2;
xobj = 0;
yobj = ymax;
zobj = Ceiling[zmax/2];
p = Join[Permutations[{1, 1, -1}], {{1, 1, 1}}];
Print["X = ", xmax, "\nY = ", ymax, "\nZ = ", zmax];
(* Loop *)
i = 0;
pos = {0, 0, 0};
k = "Start";
While[
(npos= {Mod[pos[[1]], xmax+1], Mod[pos[[2]], ymax+1], Mod[pos[[3]], zmax+1]})
!= {xobj, yobj, zobj},
i++;
Print[npos, " // ", k];
pos= npos+ (k= RandomInteger[{1,xmax}] p[[RandomInteger[{1, Length[p]}]]]);
];
Print[npos, " // ", k];
Print[i, " Moves"];
);
Invoke with
f[4]
Sample Output
X = 4
Y = 6
Z = 3
{0,0,0} // Start
{3,4,3} // {3,-3,3}
{0,0,2} // {-3,3,3}
{2,3,1} // {-3,3,3}
{0,6,2} // {3,3,-3}
4 Moves
Not sure if I'm following the rules ...