Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

A Quick Little Math Question

Cypher Ragu
[Mad Scientist]
Join date: 6 Jul 2008
Posts: 174
02-21-2009 18:01
I apologize if this might seem a bit off-topic, but it is related to scripting... Sorta...


I have frequently used llRot2Fwd for my vehicles, but I never quite understood how it worked. I searched it up on the internet, but the best explanation I could find was on the LSL wiki, and that didn't really answer my questions.


Say I wanted to do the same thing as Rot2Fwd, but just with a single angle instead of a whole rotation? What would this equation look like?




Thanks in advance ^_^
_____________________
Life is a highway... And I just missed my exit.
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
02-21-2009 21:42
oddly enough the idea was already there...

ret = <1., 0., 0.> * q;
ret.x = x_axis_angle_alone

repeat for other angles
_____________________
|
| . "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...
| -
Cypher Ragu
[Mad Scientist]
Join date: 6 Jul 2008
Posts: 174
02-22-2009 10:22
Not sure I understand...


I'm writing a program in a VERY simple language, one that doesn't have any built-in math functions, and the only data types are floats and strings. No rotations or anything like that. I'm limited to multiplication, division, addition, and subtraction.

What I need to do is basically input a euler angle and a distance, and get X and Y coordinates returned so a point can be drawn on a 2D surface.
_____________________
Life is a highway... And I just missed my exit.
Kayaker Magic
low carbonated footprint
Join date: 11 Sep 2008
Posts: 109
02-22-2009 12:31
From: Cypher Ragu

What I need to do is basically input a euler angle and a distance, and get X and Y coordinates returned so a point can be drawn on a 2D surface.

Sounds like what you need is:
X=distance*cos(theta)+Xstart
Y=distance*sin(theta)+Ystart

then draw a line from (Xstart,Ystart) to (X,Y)
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
02-22-2009 13:14
Hmm. Without trig functions, that might be difficult. You might look up the Taylor Series expansion of sine and cosine and approximate using the first few terms. I'd also suggest using trig identities to reflect your angle into the range [0 PI/4) before approximating (e.g. sin t = cos 0.5*pi-t).
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
02-22-2009 13:25
sorry, I missed the intent. I presume the language you are going to use includes math functions like sin/cos but if it doesn't here's a link to computing those manually
_____________________
|
| . "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...
| -
Cypher Ragu
[Mad Scientist]
Join date: 6 Jul 2008
Posts: 174
02-22-2009 19:29
Ok, thank you ^_^
_____________________
Life is a highway... And I just missed my exit.
missjessie Babii
Crazy Scientist #O_รถ#
Join date: 29 Jul 2008
Posts: 13
02-24-2009 04:11
Try to understand the quaternions' theory :)

From: someone


ret = <1., 0., 0.> * q;
ret.x = x_axis_angle_alone



A quaternion is like a vector and a "rotation on this vector number". I mean trough my poor English that the operation ret = <1., 0., 0.> * q; means ret = <1., 0., 0., 0 > * q; in the quaternions' space. The result is a quaternion which gives the vector after the rotation q.
The * operation isn't commutative. SO, { X , Y , Z } --( q )--> { x , y , z } /
x = <1,0,0>*q (~llRot2Fwd) (if x point at forward direction)
y = <0,1,0>*q (~llRot2Left)
z = <0,0,1>*q (~llRot2Up)

The * operator is the secret ! Look at this link to understand how this operator works in the quaternions' space (section Quaternions and the geometry of R3) :
http://en.wikipedia.org/wiki/Quaternion