Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Vector Crash Course (https://forums.graalonline.com/forums/showthread.php?t=47654)

TribulationStaff 09-02-2003 07:23 PM

Vector Crash Course
 
Q: What is a vector?
A: A vector is a way of describing motion through space, regardless of the starting point of that motion.

Q: How do you write a vector? In physics, there are two useful ways. The first is polar coordinates. Polar coordinates tells you the magnitude and the direction of the vector. So you could say some vector, say v, is this.

v = r @ theta
For example:
v = 1.75 units @ 30 degrees (or pi/4 radians if you prefer)

However, this is not exactly useful when it comes to the calculations involved. Not, at least, given that most if not all of us are more familiar with Cartesian coordinates. In Cartisian coordinates, the vector tells information about the change in x and the change in y, usually called dx and dy, respectively.

v = <dx,dy>

Based upon the Pythagorean theorem, we can write polar coordinates in terms of Cartesian coordinates and vice-versa.

dx= r*cos(theta)
dy= r*sin(theta)

r^2=dx^2+dy^2
tan (theta)= dy/dx

So, from the earlier example of polar coordinates:

v = <1.299,.75> (roughly)

Next Post: Addition and multiplication of vectors

osrs 09-02-2003 07:35 PM

in other words,vector is a mathematical device for describing a quantity that has a magnitude and a direction.

TribulationStaff 09-02-2003 07:41 PM

Right, where a scalar quantity only has magnitude.

An example: Speed is a scalar quantity that only tells distance/time. Velocity is speed in a given direction. Sorry, should have mentioned that.

osrs 09-02-2003 07:43 PM

It's interesting..

Kaimetsu 09-02-2003 07:43 PM

If you want my opinion, I'd say you went way over their heads. I don't think polar coordinates are a necessary topic, and overcomplicates matters.

osrs, anybody can copy & paste :-p

osrs 09-02-2003 07:46 PM

Quote:

Originally posted by Kaimetsu
osrs, anybody can copy & paste :-p
Yes,but since i'm studying it i know what i'm talking about.
You aren't the only one smart guy here.

TribulationStaff 09-02-2003 07:48 PM

Actually, my physics class talked about polar coordinates first, because it is more simple to understand visually.

For those of you who don't know. An angle in a graph is taken counterclockwise from the positive x axis.

Mal1core 09-02-2003 08:13 PM

what about those of us who arent doing physics. XD i only understood you in begining...

TribulationStaff 09-02-2003 08:15 PM

Scalar multiplication of vectors:

When you multiply a vector by a scalar, the direction of the vector is unchanged; only the magnitude changes. Let A=<a,b> and c be some real number. Then c*A=<a*c,b*c>.

Q: Why doesn't the direction change?
A: Think of it this way, if you have been in algebra, you should know that the slope of a line is the rise(change in y) divided by the run (change in x). Well, that is just what b and a are, respectively. So the slope of that vector is the direction of that vector. When you multiply both a and b by c, nothing changes in the slope, because c "cancels out" in the division.

Addition of vectors:

Q: How do you add/subtract vectors?
A: It is easy, once in Cartesian coordinates. Let A=<a,b> and B=<c,d>. Then A+B=<a+c,b+d>. If you wanted to subtract B instead of add it, you could just multiply it by -1, as above, then add just like you would normally.

The Scalar Product (The Dot Product)

Given two vectors, A and B, the scalar product of the two, in mathematical terms is written A·B=|A|*|B|*cos(theta), where theta is acute (or 180) angle between them. What does || mean, though? Well || returns the magnitude of the vector, making a scalar quantity. Since the dot product only involves the magnitudes of vectors, the dot prodect itself is a scalar quantity, hence the name scalar product. Using a previous example, speed is the magnitude of velocity.

Q: How do you find the magnitude of a vector?
A: Let v=<a,b>. Then, |v|=sqrt(a^2+b^2). For those with a good memory, you might recognize that to be just like the formula for finding r from Cartesian coordinates. That is because r is the magnitude of the vector.

Q: What if you don't know the angle between them?
A: That is one of the uses of the dot product. There is a shortcut way of figuring out the answer of the dot product itself. Let A=<a,b> and B=<c,d>. Then, A·B=a*c+b*d. And you already know how to find the magnitude of A and B. So just divide both sides by those magnitudes, and you are left with (A·B)/(|A|*|B|)=cos(theta). With the help of a calculator, you can find that angle.

Next post: Vector product (cross product)

TribulationStaff 09-02-2003 08:20 PM

Like I said, this is only a crash course. If you need more than what I have here, an excellent reference, if you want to sift through it, is http://mathworld.wolfram.com

marcoR 09-02-2003 08:39 PM

I took a physics course, and it was pretty easy, but I don't think I'd have the know-how to apply it to a script, I can think of some basic scripts.. but my knowledge in scripting isn't near some of yours, I will try to learn more scripting before I get into this...

Mal1core 09-02-2003 09:30 PM

same here. im still working on fairly simple things, and using every chance i get to look at new scripts posted here to learn from them.

Tseng 09-02-2003 11:56 PM

Quote:

Originally posted by osrs


Yes,but since i'm studying it i know what i'm talking about.
You aren't the only one smart guy here.

Yes, but what you stated in that thread was clearly not made from your own words, but a copy+paste job, or a direct typing of a book definition. The diction and grammar contained therein are far superior to your own.

Dach 09-03-2003 12:18 AM

Quote:

Originally posted by TribulationStaff

Q: How do you add/subtract vectors?
A: It is easy, once in Cartesian coordinates. Let A=<a,b> and B=<c,d>. Then A+B=<a+c,c+d>.

that'll confuse somebody, hurry! fix it before some unsuspecting learner hits their head on it!

The most basic use of vectors in script is just movement, many people already use them without knowing it. Whenever you have a direction (i.e. angle, or even built in directions) and a speed (magnitude) you're using vectors. Using dx (delta x or distance x, whichever you say) and dy is also using vectors, cept they don't need translation (sin + cos) to be used on the board.

I'll post some basics in physics if anyone is interested and if Gilt doesn't mind.

osrs 09-03-2003 01:21 AM

Quote:

Originally posted by Tseng


Yes, but what you stated in that thread was clearly not made from your own words, but a copy+paste job, or a direct typing of a book definition. The diction and grammar contained therein are far superior to your own.

The best answer for you is:
Shh..

marcoR 09-03-2003 01:29 AM

Lol Your both~ like stuped Lol~ man iM like so coOl`~)@@#!!

I think that did the job nicely.

Tseng 09-03-2003 03:39 AM

Quote:

Originally posted by osrs


The best answer for you is:
Shh..

Awww, no way to combat my points with logic? That's too bad.

ShadowStrike2k1 09-03-2003 04:13 AM

Quote:

Originally posted by osrs


The best answer for you is:
Shh..


Osrs, I would follow your own instructions and "Shh.." Whats the use in fighting a fight that you cant win?

osrs 09-03-2003 05:18 AM

Quote:

Originally posted by Tseng


Awww, no way to combat my points with logic? That's too bad.

I just don't care to what you say...:rolleyes:

TribulationStaff 09-03-2003 06:55 AM

Thanks for pointing out my typo, go ahead and do you physics stuff in a new thread.

adam 09-03-2003 09:42 AM

:) I had to learn polar coordinates and rectangular coordinates.

I needed to use them like constantly in AC electronics.


All times are GMT +2. The time now is 06:03 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.