How can I query the linear velocity (relative to world space) of a point of an object in PhysiJS, given the object's linear and angular velocity?
I was thinking of creating an invisible vertex on the object for this purpose, but I don't think the API even gives that capability. Do I need to calculate myself it based on translational and rotational velocity of the object? (And if so, does THREE.js or PhysiJS give a straight forward way of doing that?)
From first principles:
object.position
(1)object.localToWorld(point)
(2)object.getLinearVelocity()
(3)object.getAngularVelocity()
(4)So I need to:
For that first and third step I can use Three.js's Vector3's .sub(Vector3)
and .add(Vector3)
methods, but the middle operation is eluding me, although I'd guess a kind of multiplication. What sort of operation should I use, given that (4) can be a Euler angle or a Quaternion?
My knowledge of matrices is very limited (and rusty!) and of quaternions non-existent.
Three.js's API documentation is here
Thanks
Finally! Solved. Below is the more generic version which avoids PhysiJS. Just subsitute three's vectors with those of PhysiJS's.
scene.add(point2);
scene.add(pointAxis);
pointAxis.add(point);
angularVelocity = new THREE.Vector3( 0, 0, 0.01);
function animate(){
// rotate point around pointAxis
pointAxis.rotation = pointAxis.rotation.add(angularVelocity);
// calculate position of point in world space
var pointPosWorld = pointAxis.localToWorld(point.position.clone());
// calculate position of point in world with respect to fulcrum
var pointOffsetPos = new THREE.Vector3();
pointOffsetPos = pointPosWorld.sub(pointAxis.position.clone());
// Calculate tangential velocity
tangentialVelocity = rotate.clone().cross(pointOffsetPos);
}
I arrived at the above thanks to answer here asked in the physics stack exchange site.