Get the argument (orientation) of a 2D vector

Typically: "How do I... ", "How can I... " questions
Post Reply
DavideIng
Posts: 34
Joined: 21 Sep 2017, 17:27

Get the argument (orientation) of a 2D vector

Post by DavideIng » 24 Nov 2017, 13:50

Hello,
I am trying to implement the Particle-Swarm algorithm using a swarm of ePucks, to do that I need to get the absolute orientation (absolute argument) of a vector.
I don't know how to do that from a Threaded child script, can someone help me?

Many thanks in advance
Davide

coppelia
Site Admin
Posts: 6218
Joined: 14 Dec 2012, 00:25

Re: Get the argument (orientation) of a 2D vector

Post by coppelia » 29 Nov 2017, 09:48

Hello,

to get the orientation of a scene object's reference frame relative to the world reference frame, simply do:

Code: Select all

local eulerAngles=simGetObjectOrientation(objectHandle,-1)
Above will return the Euler angles of the frame in radians. If you however need the X, Y or Z-vector of the reference frame, then do like:

Code: Select all

local matrix=simGetObjectMatrix(objectHandle,-1)
local xVector={matrix[1],matrix[5],matrix[9]}
local yVector={matrix[2],matrix[6],matrix[10]}
local zVector={matrix[3],matrix[7],matrix[11]}
Cheers

Post Reply