[ Nomad Programming, Graphics, and Algorithms Tutorial ]
[ Part 01 - Vectors ]
[ http://nomad.openglforums.com ]
<<------------------------------------------------------>>
[ DISCLAIMER ]
I will hold no responsibility to whatever happens to you,
your computer, your sanity, your pet, or whatever that may
happen to your existence for your reading the texts given
in each tutorial. So in short, read at your own risk!
[ INTRODUCTION ]
Yes, wow, my first math tutorial! I must've bumped my head
or somethin' to think of doing this (let's just say I was never
one of the brightest person in school when it comes to math).
Anyway, I'm doing this mathematics tutorial to fill in
the gap that I've found while searching for tutorials on
graphics programming on the Internet. I hope this helps fill
the gap!...:).
The first tutorial will be about vectors in the plane. "Vector"
and "plane" are probably two of the most used words (and two of
the most basic concepts needed) in the realm of three-dimensional
graphics, that's why I'm introducing them here first.
SideNote: Everything that I will be discussing in my math
tutorial series are based on what was taught to us
(and how I understood the stuffs taught to us) at school.
[ TUTORIAL ]
So what is a vector? A vector is just a pair of real numbers
written as (for 2D vectors). If you have a 3D vector,
you will write your vector as ...simple!
To elaborate further what a vector is, a vector is both a
direction and magnitude/length. Let's say that (0,0) is the
origin and you have a vector <1,1>, then the direction of your
vector is from (0,0) towards <1,1>.
Here's an illustration:
y-axis
^
+
|
|
|
+ _ <1,1>
| /|
| /
|/
<-+---+---+---+----+--> x-axis
|
|
v
From here onwards, whenever you see: "Vec A", this means I'm
referring to a vector named A.
The next three paragraphs will be some definitions that you
probably will never read again in any of my future math
tutorials...but they are included for your knowledge and
for completeness of the topic (you wouldn't want to be
laughed at knowing all those advanced math stuffs without
knowing the basics would you?...;) ). Don't worry, the
definitions are easy...;).
o DEFINITION 1.1
The "a" in is called the (drum rolls please)
FIRST COMPONENT of the vector. The "b", on the other hand,
is called the (stop drum rolls now please) SECOND COMPONENT
of the vector. The "c" in...whazzat? You want to guess? Sure!
What's your guess? THIRD COMPONENT? Wow! How did you know?
You're a naturally born mathematician aren't you???...;).
o DEFINITION 1.2
Now, a GEOMETRIC REPRESENTATION of the 2D vector
is a directed line segment (ie, drawn like a ray) from
any point (x,y) to the point (x+a,y+b).
o DEFINITION 1.3
The GEOMETRIC REPRESENTATION from (0,0) is called the
POSITION REPRESENTATION of the vector.
Note that if I have as my vector, then I have a 2D
vector, else if I have , then I have a 3D vector!
[ OPERATIONS ON VECTORS IN 3D-SPACE ]
Things get a bit interesting here. I will now introduce
to you guys two operations that you can do with vectors
on 3D-space (aka, R^3):
1) ADDITION:
+ =
EXAMPLE:
<05,03,04> + <03,23,04> = <08,26,08> // EASY!!!
2) SCALAR MULTIPLE:
r =
EXAMPLE:
2<12,08,04> = <2(12),2(08),2(04)> = <24,16,08>
Obviously, operations on vectors in 3D-space is a no-brainer...:p.
And now, we laborously go through some properties resulting in my
introduction about operations on vectors vectors in 3D-space...
hehehe...=).
[ PROPERTIES OF ADDITION ]
1) Closure : The sum of any two vector is a unique vector
2) Commutativity: Vec A + Vec B = Vec B + Vec A
3) Associativity: (Vec A + Vec B) + Vec C = Vec A + (Vec B + Vec C)
4) Existence of Zero: There exists a Vec O such that for any
Vec A, Vec A + Vec O = Vec A
5) For every Vec A, there exists a Vec -A such that
Vec A + (Vec -A) = Vec O
[ PROPERTIES OF SCALAR MULTIPLE ]
6) Closure : For any scalar r, and for any Vec A, r(Vec A) is a
unique vector
7) Distributive : For any scalar r, and for any Vec A and Vec B,
r(Vec A + Vec B) = r(Vec A) + r(Vec B)
8) Distributive : For any scalar r, and scalar s, and for any Vec A,
(r + s)Vec A = r(Vec A) + s(Vec A)
9) For any scalar r, and scalar s, and for any Vec A,
r(s(Vec A)) = (rs)Vec A
10) Vec A(1) = Vec A
If you are one of those people who get easily intimidated by math
because of all the symbols, well, don't be. If you look closer, there
is nothing that I've written (or should I say "typed"? ;)) here that
couldn't be understood by kids who have taken up standard multiplication
and addition...;).
And now, more definitions (I know, I know, you're starting to
get annoyed with them...but be forewarned, they will exist
A LOT in my tutorial series...;) ).
o DEFINITION 1.4
The DIRECTION ANGLE of a nonzero 2D vector in the plane is
the angle Q its POSITION REPRESENTATION forms with the
positive x-axis, 0 <= Q <= 2(PI).
For example, we want to get the DIRECTION ANGLE of the
vector <-2,2>:
y-axis
^
+
| -> tan Q = -2 / 2 = -1
+ -> tan Q = -1
| -> Q = 3(pi) / 4
<-2,2> _ +
|\ |
\~+~_
\|Q \
<-+---+---+---+----+--> x-axis
|
+
v
Guess what, more definitions...;)...:
o DEFINITION 1.5
If Vec A = , we define its magnitude to be
||Vec A|| = square root(a1*a1 + a2*a2).
As an example to Definition 1.5:
||<-4,3>|| = square root(-4*-4 + 3*3)
= square root(16 + 9)
= square root(25)
= 5
o DEFINITION 1.6
A vector of magnitude / length equal to one is
called the UNIT VECTOR.
It is very important to remember Definition 1.6 since
you'll hear a lot about unit vectors when you are
programming graphics (but if you're not into programming
graphics...err...well, disregard this paragraph...:) ).
Example for Definition 1.6:
Find a unit vector in the direction of Vec A = <5,-12>:
Let's grab the magnitude first (using Definition 1.5)
||Vec A|| = square root(5*5 + (-12)*(-12))
= square root(169)
= 13
Then the unit vector in the direction of Vec A Is:
<5/13, -12/13>
Simple, don't you think so?
o DEFINITION 1.7
The DIRECTION ANGLE of a nonzero 3D vector are the
angles that its position representation forms with the
positive x, positive y, and positive z axis, respectively
named j, k, l. Note that the DIRECTION ANGLE is ALWAYS
between 0 to pi.
Some formulas for Definition 1.7 (given Vec A = ):
1) cos j = a1 / ||Vec A||
= a1 / square root(a1*a1 + a2*a2 + a3*a3)
2) cos k = a2 / ||Vec A||
3) cos l = a3 / ||Vec A||
cos j, cos k, and cos l are called the DIRECTION COSINES
of the vector. You want to know the DIRECTION COSINES of
the vector to, for example, know the angle j between a1 and
||Vec A||. Note that ||Vec A|| is the hypothenus...here's an
illustration:
/|
/ |
/ |
/ |
/ |
/ |
/ |
/_ _|
/j ) | |
+-------+-+
<--- a1 -->
Again, in the illustration above, ||Vec A|| is the hypothenus.
Guess what, MORE definitions!...
...kiddin'!...hehe...we're done actually...;).
[ ENDING ]
And that's that! Not hard eh? If there is anything that's
not clear to you, your mind, or to that part of you
that lets you comprehend the things here, you may email
me at (according to priority):
willietang@hehe.com or willietang@yahoo.com
Well, that sums up my first math tutorial. I hope you guys
like it! I'm sorry for the rather bad ASCII (or should
I say Unicode?) art...hehe...:/).
Part 2 will be about the dot product.
Briefly, the dot product accepts two vectors and the result
is a single (*cough* scalar...;)) number. Its use and purpose
you will know in Part 2!...:).
<<------------------------------------------------------>>
[ Written By: Willie Tang ]
[ Written On: 12.14.2002 ]