# Maths trigonometry problems scripting RezObject()

## Recommended Posts

Not just yours mine too Jenna  was lost with it too my little brain fried too . You must be very smart prof . you said to use quaternians rather than trig now we are both lost.

I realised the code above only works when model is set pointing exactly North any other doesn't work .

Now I have distance out from particle will this still be the same when dragon is rotated . I am guessing not as the amount on each axis will change proportionally with the rotation . For example 5 degrees will need more in y than in x . 15 degrees will need everything in x but minus . 45 degrees everything  in x positive everything south all in y minus. This said how do you calculate the amounts in x and y at a finite amount say 26 degrees or the current rotation of the dragon from llGetRot();

##### Share on other sites
Posted (edited)

I presume when I rotate my pet my distance out  calculated as above will become the hypotenuse and the opposite or adjacent will be the x and y ?

So if h = hypotonuse= my distance out a = adjacent  would be cos (theta) *h and opposite=o = sqrroot(Sqr(h) - sqr(cos (theta) *h))? maybe ?

x would be o or a and y would be o or a  depending on quadrant you was in?

Edited by VirtualKitten
##### Share on other sites
Posted (edited)

Start with a simple test harness, rezz a prim. Put a script inside that chats out the current Z angle (llGetRot()) in Radians, plus the sin and cosine of that angle, then rotates another PI/12 (15 degrees). Watch what happens to Sin and Cos as it turns through a full revolution, the values are similar but the signs change. Multiply the radius by those values of Sin and Cos and a set of X,Y points will ensue that plot a circle when added to the X,Y of the prim's position. You don't need to know the actual base forward vector, the Z component of llGetRot will always give you the object's rotation from that base forward vector.

Alternatively, as it's going to take some work, why not bite the bullet and learn to use Quarternions? The same effort you're expending trying to do this in basic trig would actually get you a passing familiarity with SL's way of doing things.

Edited by Profaitchikenz Haiku
##### Share on other sites

Can somebody explain what the actual goal/feature is, or is this purely a trigonometry puzzle?

• 1
##### Share on other sites
5 hours ago, Wulfie Reanimator said:

Can somebody explain what the actual goal/feature is, or is this purely a trigonometry puzzle?

pretty much the conversation has devolved into the second, which is fine as conversations go this way sometimes

Jenna provided the solution to the original OP question way back earlier

• 1
##### Share on other sites
Posted (edited)
3 hours ago, Mollymews said:

Jenna provided the solution to the original OP question way back earlier

The OP stated they needed a solution to work in the X Y and Z planes. "I need this to work 360  in Y and 360 Z  and X 360"

This is a problem of three degrees of rotation, one of which is global and the other two are local.

What I believe they were asking was how to convert the local rotation and position of the head into global values?

Here's a picture to illustrate.

The yellow circle represents the global rotation that the dragon linkset can have as a whole.

The green arc represents the local rotation that the neck/body can have as the dragon rears or crouches.

The red arc represents the local rotation of the side-to-side movement of the dragon's head.

The red and green arcs move together as a result of the movement around the yellow circle, the red arc moves as a result of the green arc value.

Somewhere along the bottom of the red arc is where the OP wants to rezz the fireball, but the red arc position is determined first by the green arc and yellow arc positions.

The natural (SL) way to resolve this is with rotations using * or / to apply them.

Trig will work just as well, some of the earlier solutions foundered because of the mixing of degrees together with Radians, but that was a minor issue.

Edited by Profaitchikenz Haiku
##### Share on other sites
1 minute ago, Profaitchikenz Haiku said:

a way to build this is there is a root prim and a linked emitter prim

the emitter prim is script coordinated with the custom animation set of the dragon. Offset from the root prim so that the emitter prim remains in the mouth of the dragon

when the animation to move the dragon's head plays then the linked prim is scripted to follow the arc of the dragon's head. We know what the arc is for each animation, as we created the animations

then we can emit particles (dragon breath) so that its source is the dragon's mouth

knowing the rotation and position of the emitter in the dragon's mouth (relative to the root prim) and knowing a grid target position forward of the emitter then the emitter can rez an object at the grid position. (and this is what Jenna's script does, it rezzes a prim at a target position forward of the emitter prim)

##### Share on other sites
Posted (edited)

I agree, that's a way around the calculations, and I believe VK is able to make such animations from posts elsewhere?

Edited by Profaitchikenz Haiku
##### Share on other sites
Posted (edited)
19 minutes ago, Profaitchikenz Haiku said:

I agree, that's a way around the calculations, and I believe VK is able to make such animations from posts elsewhere?

yes, VK is learning how to make just about everything that can be made

part of the learning process is coming to understand how SL functions. And in this process we learn to set aside how we think/preconceive it should work. Which can take us some time to let go of, how we think it should rather than how it actually does. And when we do get our head round this and let go of our preconceptions then it goes a lot easier for us

Edited by Mollymews
##### Share on other sites
2 minutes ago, Mollymews said:

Which can take us some time to let go of how we think it should rather than how it actually does.

Ah, point taken. I'll steer any future questions regarding trig methods back to quaternions

• 2
##### Share on other sites

yes I am still stuck with this giggles . I asked about the trig and some one said use the stuff in LSL very complex math I though as we established the distance out . I could get coordinates from  this length as the hypotenuse side and cos-sine to calculate others i was hoping for some examples in code and these could be negative or negative and positive on deferent axis depending of the angle of the emitter again you said use quaternions can you show how to do this then please as scratching my head like others  and clearly you know best prof being a kind professor. DX Thank you

Edited by VirtualKitten
##### Share on other sites

I think any future instructions are going to have to be in-world, at least two regulars on this sub-forum are indicating their exasperation with our monopolising the discussions with what are to them irrelevancies and I don't want my trouser-cuffs to get any more ragged than they already are.

• 1
##### Share on other sites

Prof I try to help everyone too but am always getting  not wearing trousers so they don't get ragged. idk in world? Are you teaching in world?

##### Share on other sites

Well I met up with the lovely professor and he showed me my rig was not root linked that is a bit of a mess silly blender made the wing the root lol. idk. that's another story .anyway he said stick with Pythagoras and trig:) Thanks Professor I hope i can get this sorted

##### Share on other sites

Ok have been thinking about this trig is not going to work here let me try and explain x y and z are controlled by head bone from armature  therefore the only change i think i need to worry about is x . This said

if we have already worked out the length of the particle by trig and call it j  and use the emitter at the center j will be the same all through Pi degrees on x on nearing x=-j see i noted radians. Further more if we assume angle is the angle of x in radians :

rot = llGetRt()

angle_rot =Eullert2Euler(rot);

angle -= angle_roy.x;

if (angle ==llPi ){ x _axis =  -j;y_axis = 0 } else if((angle ==0){ x _axis =  j;x_axis=0} else if(angle == PI_BY_4)  {y_axis = j; xaxis = 0;} else if angle == PI_BY_3) {y_axis = -j; x_axis = 0;} else if (angle>PI_BY_2) angle = llPi-angle;

//We then have a triangle with two sides the length of J this is a problem as angle if more than 90 we cant use trig so best not use it at all.
//with two sides J and to calculate other side base , we cannot use Pythagoras either .My memory now gets hazy  it would be better to ignore Trig and Pythagoras for this as we would solve the y without breaking it down further.

How do we do this with out Pythagoras or Trig? thank you for looking? nope didn't work at all

Edited by VirtualKitten
##### Share on other sites

idk none of this works need help ? maybe better in quaternions is lost apart from blender renamed my objects 1.object,2.object,3.object etc to sort first for root.

Edited by VirtualKitten
##### Share on other sites

You have a notecard awaiting you inworld, but the short answer is,

vector * rotation is equivalent to <vector_x*Sin(angle1), vector_y*Sin(angle2), vector_z*Sin(angle3)>

Nice drawing, by the way.

• 1
##### Share on other sites
On 5/4/2021 at 3:47 PM, Profaitchikenz Haiku said:

I think any future instructions are going to have to be in-world, at least two regulars on this sub-forum are indicating their exasperation with our monopolising the discussions with what are to them irrelevancies and I don't want my trouser-cuffs to get any more ragged than they already are.

You're fine!

• 1
##### Share on other sites

Generally, may I recommend the following articles too?     The first one, by Chalice Yao, may offer a solution to the OP's question, since, as Chalice explains,

Quote

Here is a little snippet for the rotationally-challenged, or those who have some complex solution but want something much simpler.
How to rotate an object so it points its X axis (which is the 'forward' axis on prims) towards another object?

so it may help with the OP's question.    The second two, by Grandma Bates, are excellent introductions to SL rotations and quaternions, which I found really aren't difficult once someone who knows what she's talking about and who knows how to explain things simply (like Grandma) took me through them*

*ETA:  And Void Singer, of course (anyone searching for help on rotations in the forum archives will see how tirelessly patient she was with me and a lot of other people!).

Edited by Innula Zenovka
• 3
##### Share on other sites

Those three are excellent guides and really should be stickied in this thread, BUT

In this instance and in a few others, there were a couple of stumbling-blocks

People with a build in progress are reluctant to put it to one side and go back to school, or to build small simple test rigs to investigate how to do something, they're stuck to their build

Builds that have not been put together with a view to subsequent puppeteering/actioning cause problems that cannot be resolved by studying rotations.

That said, it was another fine mess I   another great adventure to liven up the week.

I have great hopes Molly and Quistessa's work in another thread are going to be of assistance in future adventures.

ETA

The answer to the OP's problem by the way, I never got around to explaining to them because the discovery of the other issues took over.

There was an emitter prim in the mouth of the dragon which spat flames as a particle stream. It always spat them in the correct direction no matter which way the dragon was pointing, and I was going to explain to the OP that within that child prim, a call to llGetPos() would know where in the region the mouth was, a call to llGetRot() would get the emitter prim rotation in region directions, and as the emitter Z-axis was the direction in which the particles were streaming, the expression llGetPos() + <0.0, 0.0, 2.0>*llGetRot() would therefore give the region position for rezzing the object, regardless of the root rotation. It really was that simple, one line of script. I built a test harness to demonstrate this but it never had the chance to be shown.

I had a cunning plan, to let the OP to work the position out by Trig as they had insisted they wanted to do, and then demonstrate that the one line did the same, but faster and with less pain. Like all cunning plans, it came to rest on the reefs of reality.

Edited by Profaitchikenz Haiku
• 1