arraycoord


The arraycoord function returns a coordinate array for the linear index into a multi-dimensional array. All coordinates are returned as integral values. This is the inverse of arrayindex, which converts a coordinate array to a linear index.

Syntax

Coord_Array = arraycoord( Axis_Array, nIndex )

bullet.gif    where Axis_Array is a lua table (indexed array) containing the array dimensions, starting from the most rapidly varying index in element [1]

bullet.gif    nIndex is the linear index into the Axis_Array.

bullet.gif    Coord_Array is returned as an n-dimensional array containing coordinates, with the most rapidly varying index in element [1].

bullet.gif    On failure, nil is returned.

Examples

The following script returns a coordinate array based on the linear index and the axis lengths of the array.

axis = { 512, 1024, 2}

-- array containing the axis lengths

index = 544391

-- linear index into the array

x = arraycoord( axis, index )

-- find the coordinate array x

if x == nil then Exit("Bad Coord") end

-- test the returned coordinate array

for n = 1, #x do

-- for each element in the coordinate array

  Printf("%d, ", x[n])

-- list the coordinates

end

-- result: 125, 40, 2,

Related Topics

Array Functions

arrayindex


Mira Pro x64 Script User's Guide, v.8.77 Copyright Ⓒ 2024 Mirametrics, Inc. All Rights Reserved.