Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / 3D Vectors - positions and angles - explanations needed

Author
Message
nz0
AGK Developer
16
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 19th Apr 2017 00:52
I have fumbled around with vectors in various forms, but I think it would be incredibly useful if someone could explain in plain English how to use positional vectors and directional vectors, with real uses of the various vector functions, such as dot and multiply in terms I can understand.

e.g.

* using positional vectors to describe 2 objects and then:
* using directional vectors to describe the angle between the 2 objects
* normalising vectors explained

One second it all makes a kind of sense, then the next I start getting mixed up with positional vectors and directional vectors and how they work together.

I would like to fully switch my brain over to using vectors instead of doing loads of maths to find x,y,z angles and distances or cheating by using XZ in 2D calculations and faking Y etc.

Jack
19
Years of Service
User Offline
Joined: 4th Oct 2004
Location: [Germany]
Posted: 19th Apr 2017 01:14
This is a case for:
'favorite search machine'
https://en.wikipedia.org/wiki/Vector_(mathematics_and_physics)
Youtube will even give you visual references.



[/url]
Stab in the Dark software
Valued Member
21
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 19th Apr 2017 01:53
Here is a function I wrote to help someone recently on this forum with getting a direction vector for 3D physics.
It includes a normalizing function which just simply converts all the vector values to be between 0.0 and 1.0.
Also a function to get the angle between 2 3D position vectors.

The coffee is lovely dark and deep,and I have code to write before I sleep.
nz0
AGK Developer
16
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 19th Apr 2017 02:07
Thanks for the example stab. However, a float value for a 3D angle means what exactly?

I understand 2D angle, but how do I convert a float to an X,Y,Z angle?
nz0
AGK Developer
16
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 19th Apr 2017 02:08
Quote: "This is a case for:
'favorite search machine'
https://en.wikipedia.org/wiki/Vector_(mathematics_and_physics)
Youtube will even give you visual references.
"


I've looked at a lot of this. I'm asking for a correlation between "that" and how to implement in AGK..
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 19th Apr 2017 02:11
A positional vector is really nothing more than a point in space. Vector is a fancy way to say point! If you have an object position at [x,y.z] then you can say that is its positional vector.

Directional vectors point towards a direction of space and are generally normalized. A normalized vector (also can be called a unit vector) only means that it has a length of 1. So if you draw a line from the origin [0,0] to the coordinates of the directional vector, that would show you the direction. Why normalize? Because then it's easy to move objects in that direction. By multiplying the directional unit vector by a scalar (single value), like the speed of your spaceship, you can determine how far to move on the X, Y, and Z axis.

Technically, you can't look at a directional and positional vector and tell them apart, it's kind of the same thing. It's how the vector is being used. But as I said, if the vector is normalized, it's probably being used for some sort of direction.

How do you normalize a vector? Divide each component by the vector's length. The length of a vector is nothing more than using pythagorean theorm. So take the square root of the sum of each component squared.

length = sqrt(V.x^2 + V.y^2 + V.z^2)

N.x = V.x / length
N.y = V.y / length
N.z = V.z / length

To convert an angle into a directional vector, use SIN and COS.

X = COS(angle)
Y = SIN(angle)

No need to normalize this as they already will be.

For example, say you want to move your spaceship at [x,y] by 10 units pointing at 38 degrees.

x = x + cos(38)*10
y = y + sin(38)*10


On my site I keep a list of vector calculations, they might interest you.
http://www.zimnox.com/resources/articles/math/?ar=m001

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds

Attachments

Login to view attachments
Stab in the Dark software
Valued Member
21
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 19th Apr 2017 03:14
Quote: "Thanks for the example stab. However, a float value for a 3D angle means what exactly?

I understand 2D angle, but how do I convert a float to an X,Y,Z angle?"


The function returns an angle in radians which is a float.
The coffee is lovely dark and deep,and I have code to write before I sleep.
MadBit
VIP Member
Gold Codemaster
14
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 19th Apr 2017 08:55
nz0 wrote: "I understand 2D angle, but how do I convert a float to an X,Y,Z angle?"


It does not matter if you measure the angle between two lines in the 2d or 3d world. It is just the angle between these two lines.
What you mean with X, Y, Z angle is actually a directional vector. Converting back the angle in one direction is somewhat more difficult.
This requires the Up-Vector and the Look-At Vector (directional vectors). So how your object is actually oriented. From this base you can then calculate a new look-at vector.

This is a good site for more information and 3d-maths.
Share your knowledge. It\'s a way to achieve immortality. (Tenzin Gyatso)
Pixie-Particle-Engine
nz0
AGK Developer
16
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 20th Apr 2017 01:54
Thanks for the info.

I've patched together enough stuff to see me along at the moment.

It occurred to me that AppGameKit may be well served if you could apply vectors to objects directly, instead of converting between euler and vectors?

I'll continue to mess around with what I've got until it sinks into my dumb head.
Golelorn
7
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 20th Apr 2017 02:23
Awesome resources. Thanks so much, guys.

Login to post a reply

Server time is: 2024-05-02 17:30:43
Your offset time is: 2024-05-02 17:30:43