Vectors: Difference between revisions

From Graal Bible
Line 34: Line 34:


=== Vector Subtraction ===
=== Vector Subtraction ===
[[Image:Vectors-subtraction.png|thumb|left|Vector subtraction]]
[[Image:Vectors-subtraction.png|thumb|right|Vector subtraction]]
With these two properties, we find that vector subtraction is possible, and no longer a new idea. This is done in GraalScript with the use of the '''vectorsub({{graycourier|u}},{{graycourier|v}})''' function. <br />
With these two properties, we find that vector subtraction is possible, and no longer a new idea. This is done in GraalScript with the use of the '''vectorsub({{graycourier|u}},{{graycourier|v}})''' function. <br />
  u-v = u + (-v) = u + (-1)&#183;v
  u-v = u + (-v) = u + (-1)&#183;v

Revision as of 12:16, 21 November 2006

Vectors are mathematical representations of any thing that has a length, or magnitude, and direction.

Definition

In GraalScript, a vector is limited to three dimensions, however, mathematics allows for analyses of vectors in n-dimensions. Vectors do not have position, however. Two vectors are said to be parallel if they have the same direction (u || v), and are said to be equal if they are parallel and have the same magnitude (u = v). Vectors are generally described by their terminal points with respect to the origin (0,0,0).

The basic format of a vector in GraalScript is {x,y,z} where x, y, and z are all floating points in reference to the axis to which they correspond. Built into GraalScript are several functions which can be used to analyze these vectors.

In mathematics, vectors are often written

v = <v1,v2,v3>

for a vector in three dimensions. They can also be written as the sum of unit vectors, i = <1,0,0>, j = <0,1,0>, and k = <0,0,1> on the x, y, and z axes, respectively. In this case, the vector would be written as

v = v1i + v2j + v3k

where the values of v are treated as scalars (numerical multipliers) of the unit vectors.

To denote the difference between a scalar and a vector, vectors are often written with a directional arrow above them, which looks like the top half of an arrow pointing right. In GraalScript, a scalar and a vector are impossible to confuse: a scalar is a floating point whereas a vector is a string.

Vector Length (Magnitude)

Being as vectors are merely written by terminal point coordinates, there is no immediate way to determine the magnitude of the vector. Mathematically, the terminal point lies on a sphere that has the same radius as the vector's magnitude. Thus, we can use the equation of a sphere to calculate the magnitude.

r2 = x2 + y2 + z2
r = √(x2 + y2 + z2)

where r is the magnitude. Generally, the magnitude is denoted as |v| or ||v||. This was chosen, because absolute value refers to distance from the origin, thus the marks were suitable. In GraalScript, however, the magnitude of any vector can be calculated simply by plugging a vector string into the vectorlen(v) function.

Vector Modification

Along with vectorlen are a plethora of functions built into GraalScript all for the purpose of modifying vectors.

Vector Addition

Vector addition

Given the vectors u and v, we could create a third vector that has the magnitude of u and v, were the two vectors to be placed tip-to-end. This is called vector addition and can be done with the function vectoradd(u,v). This takes the terminal coordinates and adds them together. to make a new vector:

w = <u1+v1, u2+v2, u3+v3>. 


Vector-Scalar Multiplication

With a vector, v, and a scalar, s, we could make a new vector that is s times larger than v. This can be accomplished in GraalScript with the function vectorscale(v,s). The vector is thus extended in the following manner:

s·v = s·<v1,v2,v3> = <s·v1,s·v2,s·v3>.

Vector Subtraction

Vector subtraction

With these two properties, we find that vector subtraction is possible, and no longer a new idea. This is done in GraalScript with the use of the vectorsub(u,v) function.

u-v = u + (-v) = u + (-1)·v

You can imagine this as the two vecotrs placed tip-to-end, but the second is facing the opposite direction.

Other functions

vectordot(u,v): see Dot Product.
vectorcross(u,v): see Cross Product.