Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

vector math

Quince Farber
Registered User
Join date: 14 Jan 2005
Posts: 9
09-17-2006 19:41
Short question:
"how can I learn quickly about vector math" or "How can I learn how some basic vector equations" (I'm already trying to use the data listed in the wiki)


Message:
I'm trying to understand vector math. Like calculating a the length between two points, and then calculating any point on that line by a trace value. I'd also really like to learn how to covert overlaying vector grids. To do tasks like converting a vector in local space to an equivalent vector in global space. (while taking into account the rotation that would effect the result) The 3rd task I have interest in, rotate an object on one or many axis to face a vector

If your willing to teach, write the code (willing to pay), or just know of a great web site, any help would be appreciated.
ed44 Gupte
Explorer (Retired)
Join date: 7 Oct 2005
Posts: 638
09-17-2006 20:23
Hi Quince

from
http://rpgstats.com/wiki/index.php?title=LlVecDist
distance between two points:
float llVecDist(vector v1, vector v2) // allways a positive float

Calculating any point on that connecting vector:
I am open to correction here:
CODE
float vecDist = llVecDist(v1, v2) // allways positive, so order does not matter here
vector lever = v2 - v1;
vector positionOnLine = v1 + (lever * wantedFractionOfDistance/vecDist);


Overlaying vector grids:
Think of calculating the lever from above on v1 that has 0 rotation. If v1 rotates, you multiply the lever vector by the v1 rotation. The lever's magnitude is still the same. Of course, the target object rotation should also be rotated by the v1 rotation.

if v1 had some rotation to start with, then you need to divide the lever vector by the original rotation of v1 before multiplying by the new rotation of v1.


All rotations should be in quarternians. They are wonderful because they work when applied to levers and other rotations. lsl has functions to convert from vectors (Euller) to quarternians.

I have posted a simple script to swing an uncut door around an arbitrary axis at:
/15/f4/135162/1.html
Lex Neva
wears dorky glasses
Join date: 27 Nov 2004
Posts: 1,361
09-18-2006 11:06
From: ed44 Gupte

Calculating any point on that connecting vector:
I am open to correction here:
CODE
float vecDist = llVecDist(v1, v2) // allways positive, so order does not matter here
vector lever = v2 - v1;
vector positionOnLine = v1 + (lever * wantedFractionOfDistance/vecDist);



Close! Something more like this:

CODE
float vecDist = llVecDist(v1, v2) // allways positive, so order does not matter here
vector lever = llVecNorm(v2 - v1); // a vector of length 1 pointing from v1 to v2
vector positionOnLine = v1 + (lever * wantedFractionofDistance * vecDist);


The two changes I made were to turn lever into a unit vector and to use multiplication instead of division for wantedFractionofDistance. Actually, I'm just realizing that this can be made much more simple and still do the same thing:

CODE
vector path = v2 - v1; // if you add path to v1, you'll end at v2
vector positionOnLine = v1 + (wantedFractionOfDistance*path);


As the comment says, adding the entire path vector to v1 gets you to v2. If you add only half of it, you get halfway to v2.
SuezanneC Baskerville
Forums Rock!
Join date: 22 Dec 2003
Posts: 14,229
11-25-2006 08:11
Suppose you wanted to find a point along the path between v1 and v2 but instead of wanting to find a point a fraction of the way along that path you instead wanted to find a point on that path a certain distance away from point v2. How would you find that in LSL?
_____________________
-

So long to these forums, the vBulletin forums that used to be at forums.secondlife.com. I will miss them.

I can be found on the web by searching for "SuezanneC Baskerville", or go to

http://www.google.com/profiles/suezanne

-

http://lindenlab.tribe.net/ created on 11/19/03.

Members: Ben, Catherine, Colin, Cory, Dan, Doug, Jim, Philip, Phoenix, Richard,
Robin, and Ryan

-
2k Suisei
Registered User
Join date: 9 Nov 2006
Posts: 2,150
11-25-2006 08:23
From: SuezanneC Baskerville
Suppose you wanted to find a point along the path between v1 and v2 but instead of wanting to find a point a fraction of the way along that path you instead wanted to find a point on that path a certain distance away from point v2. How would you find that in LSL?



Just add the fraction to V2 instead of V1
Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
prob not the best way
11-25-2006 09:28
From: SuezanneC Baskerville
Suppose you wanted to find a point along the path between v1 and v2 but instead of wanting to find a point a fraction of the way along that path you instead wanted to find a point on that path a certain distance away from point v2. How would you find that in LSL?


path points from v1 to v2. I think there is a function to normalize it, ie make it 1 unit long. Then multiply it by your desired distance and add it to v1. Not tested...

CODE

vector path=v2 -v1;
path = path / llLength(path);

vector newpos = v1 + distance * path;


next time, pay more attention in HS geometry ("I'll never need to know this in real life!";) 8-)

My apology. I was just trying to make a joke.
SuezanneC Baskerville
Forums Rock!
Join date: 22 Dec 2003
Posts: 14,229
11-25-2006 14:25
From: Lee Ponzu
llLength

There is no llLength. Next time pay more attention to the LSL wiki.

From: someone

next time, pay more attention in HS geometry


I was in a state of total engrossment in high school geometry. I loved it. However, it's been over 30 years since I was in high school geometry. As surprising as it might be, it's not as fresh in my mind now as it was back then, but this lack of freshness has nothing to do with not paying attention.

I asked this in response to a question from someone else; I didn't poke fun at them for not knowing, instead I took the time to try a little test script, and when it failed, I asked a question in the forums for them.

The function for determining the distance between two point vectors is llVecDist, and the function for normalizing a vector is llVecNorm.
_____________________
-

So long to these forums, the vBulletin forums that used to be at forums.secondlife.com. I will miss them.

I can be found on the web by searching for "SuezanneC Baskerville", or go to

http://www.google.com/profiles/suezanne

-

http://lindenlab.tribe.net/ created on 11/19/03.

Members: Ben, Catherine, Colin, Cory, Dan, Doug, Jim, Philip, Phoenix, Richard,
Robin, and Ryan

-
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
11-25-2006 23:40
I'd actually just start at: http://en.wikipedia.org/wiki/Vector_%28spatial%29
Lex Neva
wears dorky glasses
Join date: 27 Nov 2004
Posts: 1,361
11-26-2006 10:54
From: SuezanneC Baskerville
Suppose you wanted to find a point along the path between v1 and v2 but instead of wanting to find a point a fraction of the way along that path you instead wanted to find a point on that path a certain distance away from point v2. How would you find that in LSL?



CODE

vector direction = llVecNorm(v1 - v2);
vector point = v2 + direction * distance;


In english: let direction be a unit vector that points from v2 to v1. Now start at v2, and move out "distance" units in the direction of v1.