Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

How to Multiply Vectors?

Nyx Alsop
Registered User
Join date: 14 Dec 2008
Posts: 252
01-16-2010 13:58
How can I do this?

touch_start(integer total_number)
{

vector vecOne = <10, 5, 10>;
vector vecTwo = <5, 5, 5>;
vector vecThree = vecOne * vecTwo;

llSay(0, (string)vecThree);
}
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
01-16-2010 14:08
From: Nyx Alsop
How can I do this?

touch_start(integer total_number)
{

vector vecOne = <10, 5, 10>;
vector vecTwo = <5, 5, 5>;
vector vecThree = vecOne * vecTwo;

llSay(0, (string)vecThree);
}
You have two ways. The way you do it it is a DOT product and produces a float:
float f = vecOne * vecTwo;
The other product is a CROSS product and results in a vector perpendicular to both vectors in the argument:
vector vecThree = vecOne % vecTwo;
_____________________
From Studio Dora
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
01-16-2010 14:26
if you are expecting a result of <50, 25, 50> you'll need to multipl each element separately....

vector vecOne = <10, 5, 10>;
vector vecTwo = <5, 5, 5>;
vector vecThree = < vecOne.x * vecTwo.x, vecOne.y * vecTwo.y, vecOne.z * vecTwo.z >;

alternatively, if you know all the elements in one of the vectors are the same, you can do this

vector vecOne = <10, 5, 10>;
float fltTwo = 5.0;
vector vecThree = vecOne * fltTwo;
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
01-16-2010 14:34
There's a big difference between vector multiplication (dot product or cross product), which Dora was describing, and scalar multiplication, which is what Void was describing. The OP better be sure that he knows which one he wants to do.
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask.... ;)

Look for my work in XStreetSL at
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
01-16-2010 15:11
yup, and many expect the latter to occur with the former operator...

out of curiousity, would my first example actually be considered scalar? I'd think so, just with a variable magnitude, versus a universal one... but I'm not sure... calc was so long ago.

ps is it just me or are operators and precedence (my two original post excepted) coming up a lot more recently?
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Nyx Alsop
Registered User
Join date: 14 Dec 2008
Posts: 252
01-16-2010 15:28
I understand what a dot product is, but could someone tell me why it's usful? I know it's the same in Matrix multiplcation, but I never really understand why it's useful?
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
01-16-2010 15:43
The dot product of two vectors a and b is == |a| *|b| *cos Theta, where |a| and |b| denote the length of a and b and Theta is the angle between them. Among other things, this means that given two vectors, the angle between them can be found by rearranging this to get

Theta = arccos (( a . b)/(|a| *|b|)) .

Kind of a useful function.
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask.... ;)

Look for my work in XStreetSL at
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
01-16-2010 15:56
also useful if you want to do matrix operations using vectors to store the lists instead of storing all those variables separately and then doing it all long hand... makes solving equations in 2 coefficients a heck of a lot faster =)
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
01-17-2010 02:59
From: Nyx Alsop
I understand what a dot product is, but could someone tell me why it's usful? I know it's the same in Matrix multiplcation, but I never really understand why it's useful?
The dot product is useful in many ways. In relation to SL i is useful to find out if two vectors are perpendicular, they are if the dot product equals zero. Do two vectors point in the same direction? They do if the dot product of the normalized vectors equals one. If the dot product of the normalized vectors equals minus one, the two vectors point in opposite directions. For more math and more uses take a look at this site:
http://en.wikipedia.org/wiki/Dot_product
_____________________
From Studio Dora