The angle and magnitude of a vector is calculated from the x and y and z coordinates in Famo.us.
Understanding Magnitude will help you here. Magnitude is a measure derivative of the vector calculated by using the coordinates. Magnitude is the length of the vector. You can learn about magnitude in Kahn academy. There is no way to know a vector values based just on knowing the Magnitude.
Back to what you want to accomplish using Famo.us.
Basic Explanations of Particle
A particle in Famo.us is based on it's velocity, position and force. So, we have to know the vector of the angle to set a velocity of the particle in Famo.us. There currently is not a method to be able to pass the angle and have the velocity set.
Creating an example of having a constant Magnitude in Famo.us
Working Example Code on jsBin
Setup up the original Vector
var impulse = 0.01;
var vector = new Vector(1,1,0);
// Setup our maximum Magnitude to the magnitude of our vector
var maxMagnitude = vector.norm();
Set the force to be an impulse on the particle to keep it in motion. Set our velocity to the maximum magnitude to control our constant speed.
Note: Magnitude in a Particle in Famo.us is particle.norm()
. Not sure why they did not call it magnitude.
function setForce() {
// Apply an impulse to the current vector keep it in motion
this.applyImpulse(this.velocity.cap(impulse));
// set the velocity speed to be a max in units
this.setVelocity(this.velocity.cap(maxMagnitude));
// Return the particles transform value
return this.getTransform();
}
Transform from the Particle Transform
var physicsEngine = new PhysicsEngine();
var particle = new Particle({
mass: 1,
position: [100, 100, 0]
});
var modifier = new Modifier();
modifier.transformFrom(setForce.bind(particle));
var surface = new new ImageSurface({
content: 'http://code.famo.us/assets/famous_logo.svg',
size: [radius * 2, radius * 2],
properties: {
borderRadius: (radius * 2) + 'px'
}
});
physicsEngine.addBody(particle);
context.add(modifier).add(surface);
//Start the particle in motion
particle.setVelocity([vector.x, vector.y, 0]);