Suppose we have a coordinate system with two points and and the origin , then the length of the vector defines the magnitude of the force given by the scalar value of :
symmetrically the length of the vector defines the magnitude of the force given by the scalar value of :
The sum of the two forces and applied in the point-mass can be computed from the sum of the segments that define them.
Let and , then the sum of the two vectors is:
where is the midpoint of the segment . Thus the resulting force is:
The scalar value of is given by:
Note that in the illustration shows an ideal case where the component is zero and forces are applied from the origin (point-mass force).
In Euclidian space the resultant force can be calculated as such that:
where represents the basis vectors:
this can be generalised to n-dimensional Euclidian space by extending the components of the vectors.
The magnitude of the vector is given by the scalar :
For a vector in 2D defined as:
with the basis vectors:
in the triangle we can write that:
due to the right angle formed by . Thus, we can deduce that the angle (in radians) is:
Note that the length of the segment is given by the magnitude of the vector and that represents the component of the vector on the axis.
Let us take a real-world scenario. We want to calculate the direction of the wind in terms of bearing (North
, South
, East
, West
) and we know that the measured wind vector is:
For aesthetics, let us presume that the axis represents North
and that the axis represents East
(with West
and South
in the respective inverse sense of the axis). Now we take the vector and want to point in the direction of the wind. In order to do that, we perform the calculations above an obtain the angle :
and converting to degrees, we obtain:
This means that we have to rotate an arrow, or a pointer, starting from the axis, approximately towards the axis that we have decided represents North
. The result makes sense if you think about it, because the vector is in the first trigonometric quadrant (more than zero and less than 90
degrees). So, interpreting the result, the wind direction is approximately towards the North-North East
.
Given two points in cartesian space and , we want to find the unit vector between those points. First, we establish from which point to which point the direction should be.
For example's sake, let us assume that we want to find the vector that points from to . In that case, the vector is:
In order to find the unit vector, we dive the vector with its magnitude. In other words:
In order to compute we can use the cartesian notation of vectors using matrices, such that:
and the magnitude of the vector is given by the scalar :
Using Second Life, Suppose we have two arbitrarily disposed masses in space, the red ball and the cyan ball:
and that we want to apply an impulse to the red ball, such that it travels towards the cyan ball.
In order to propel the red ball towards the the cyan ball, we apply the formulas above as a script inside the red ball. We perform the following calculations in succession:
// velocity in m/s float velocity = 1; default { state_entry() { // scan for an object named cyan llSensor("cyan", "", ACTIVE|PASSIVE, 96, TWO_PI); } // when the cyan ball is found sensor(integer num) { // calculate the vector between the cyan ball and the red ball vector f = llDetectedPos(0) - llGetPos(); // calculate the unit vector vector u = (f)*1/llVecMag(f); // apply an impulse to the red ball llSetVelocity(velocity * u, FALSE); } }
The unit vector u
gives us the direction and the scalar velocity
gives us the speed. The reason for having an unit vector is that we leave it up to the scalar multiplier u
to give us the velocity.
The law for universal attraction of masses is given by the formula:
where:
As a small application of our cyan and red balls, let us rename both balls to mass
and size them so that their sizes are equal. Under these constraints, we can use the following script, placed in both balls to illustrate the universal attraction of masses:
default { state_entry() { // scan for an object named mass llSensorRepeat("mass", "", ACTIVE|PASSIVE, 96, TWO_PI, 1.175494351E-38); } // when the cyan ball is found sensor(integer num) { // calculate the vector between the cyan ball and the red ball vector f = llDetectedPos(0) - llGetPos(); // calculate the unit vector vector u = (f)*1/llVecMag(f); // get the distance between the cyan ball and the red ball float d = llVecDist(llDetectedPos(0), llGetPos()); // the force is equal to the directional vector times the // mass squared and divided by the distance between the masses llSetForce(u * llPow(llGetMass(), 2)/d, FALSE); } }
Since we now know how to use the directional vector u
from the previous section, we can now set the force as the unit vector u
times the force. Since we have said that we will consider the masses to be equal, we can just square the masses instead of doing and then divide with the distance between them.
The masses do not necessarily have to be the same, however, in Second Life, it is impossible to detect the mass of an object. A different restriction is the force is applied every which is roughly the resolution that events in Second Life are capable of.
One consequence of the universal law of attraction is the creation of orbits.
Given two masses, the following observations can be made initially:
In the real world, given the lack of constant acceleration, the orbit decays. This can be explained by looking at the forces exerted upon the orbiting object.
Suppose that the object is in and that the initial force acts upon the object, that the force due to the universal attraction of masses is and that the resultant is . In the triangle formed by we can write:
and thus:
and if the initial force is gradually diminished we observe that the angle becomes smaller such that eventually:
the angle will be , thus pulling the object towards the object . Object 's orbit will decay and eventually collide with object
The magnitude of the centripetal force of an object of mass moving at a tangential speed along a path with radius of is:
in terms of angular velocity , the equation can be written as:
where, in two dimensions:
and is the change of angle in time.
Given a central pole, and a ball that must rotate around the pole at a given velocity (here ), the following script will:
float velocity = 0.1; default { state_entry() { // scan for an object named mass llSensorRepeat("pole", "", ACTIVE|PASSIVE, 96, TWO_PI, 1.175494351E-38); } // when the object is found sensor(integer num) { // get the position of the object vector oPos = llDetectedPos(0); // get our position vector mPos = llGetPos(); // calculate the vector between the object and us vector f = <oPos.x, oPos.y, 0> - <mPos.x, mPos.y, 0>; // calculate the unit vector towards the object vector u = (f)*1/llVecMag(f); // calcualte the unit vector rotated by 90 (tangential) vector r = u * llEuler2Rot(<0, 0, 90> * DEG_TO_RAD); // get the distance between the object and us in the plane xOy float d = llVecDist(<oPos.x, oPos.y, 0>, <mPos.x, mPos.y, 0>); // compute the vector for the centripetal force vector fc = u * (llGetMass() * llPow(velocity,2)/d); // compute the vector for the velocity vector v = r * velocity; // set the centripetal force llSetForce(fc, FALSE); // set the tangential velocity llSetVelocity(v, FALSE); } }
The velocity is favourably selected as being small in order to counter the effect of the application of the centripetal force fc
every . In reality, the centripetal force is applied all the time and not in intervals, which, in the simulation's case, makes the ball gradually spiral away from the pole.