Data manipulation/transformation

Data in CoppeliaSim can transformed in various ways:

  • data packing/unpacking
  • linear algebra functionality
  • image processing
  • path data transformation
  • sim.transformBuffer
  • other matrix/transformation related functions
  • Following example illustrates how to pack/unpack data. Other functions can be found here:

    -- Packing/unpacking specific type of data: local data={1,2,3} local binaryPackedData=sim.packDoubleTable(data) -- binary packing data=sim.unpackDoubleTable(binaryPackedData) -- binary unpacking base16=require('base16') local base16PackedData=base16.encode(binaryPackedData) -- base16 encoding binaryPackedData=base16.decode(base16PackedData) -- base16 decoding base64=require('base64') local base64PackedData=base64.encode(binaryPackedData) -- base64 encoding binaryPackedData=base64.decode(base64PackedData) -- base64 decoding local base64Buffer=sim.transformBuffer(binaryPackedData,sim.buffer_uint8,1,0,sim.buffer_base64) local originalBuffer=sim.transformBuffer(base64Buffer,sim.buffer_base64,1,0,sim.buffer_uint8) -- Packing/unpacking random data: local data={1,'hello',{value='world'},{1,{2,3}}} local binaryPackedData=sim.packTable(data) -- binary packing data=sim.unpackTable(binaryPackedData) -- binary unpacking cbor=require('cbor') local cborPackedData=cbor.encode(data) -- cbor encoding data=cbor.decode(cborPackedData) -- cbor decoding

    More packing/unpacking functions can be found here.


    Following example illustrates usage of the linear algebra functionality:

    -- Get the absolute transformation matrices of an object and its parent: local absObj=Matrix4x4:frompose(sim.getObjectPose(objectHandle,-1)) local absParentObj=Matrix4x4:frompose(sim.getObjectPose(parentHandle,-1)) -- Compute the relative transformation matrix of the object: local relObj=Matrix4x4:inv(absParentObj)*absObj -- Get the relative transformation matrix of the object directly: local relObj2=Matrix4x4:frompose(sim.getObjectPose(objectHandle,parentHandle)) -- Check that both matrices are same: print(relObj:sub(relObj2):abs():max())

    The documentation for the linear algebra functionality can be found here.