Вопрос

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:

  • Given object.position (1)
  • Given position of point in world space object.localToWorld(point) (2)
  • Given object.getLinearVelocity() (3)
  • Given object.getAngularVelocity() (4)

So I need to:

  • Subtract (1) from (2) to give point's offset in world space (5)
  • Use (4) and (5) to get linear velocity of point relative to object (6)
  • Add (6) and (3) to get total linear velocity of point

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top