Jump to content

Small math problem. (rotations, with pictures!)


Wulfie Reanimator
 Share

You are about to reply to a thread that has been inactive for 2062 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Here's a little visual for what I'm about to ask (I lied, there's only going to be a single picture):


1: First rotation at <0,0,0> (euler)
2: Second rotation
3: Third rotation
Black dot: Object center
White dot: Center of rotation
Grey circle: Projected location for object center given any angle around the X axis.

Given a prim (box/cylinder) with an abitrary size with one axis being longer and able to change its length while the script is running, how do I set an object's rotation while keeping one end "anchored" in its place? (Rotating around an offset point.)

There's an example on the SL Wiki, but it results in relative rotation. For example, running the same code twice would cause two rotations with the same angle size. What I want to do is set the rotation in global coordinates so that running the same code twice would cause one rotation and no change the second time.

In short, I want to know/understand the math required for this. I can script, I just can't do the math.

Additional notes for context:
- The rotation can be around multiple axes at once. (<45,90,30> euler)
- The center of rotation or "anchor point" is known.

- The prim is part of a link set and worn as an attachment.
- The length of the Z axis can be anything above 0.1 and max prim size.

Link to comment
Share on other sites

Because rotations always happen around an objects center, what you want to do involves not only changing the rotation of your object, but its position as well. If your image accurately depicts what you want to do, and the rotation and position of the object will always be one each of the three you illustrate, you can store them in a list, or use another value storage system, and change the object's position/rotation with references to those variables.

Link to comment
Share on other sites

    I can offer another solution based on what I can see of what you want to do. If you make profile cuts on your object, so that the object center and its center of rotation (its end or anchor point)  are the same, you would only have rotations to worry about. This is a strategy sometimes used to make doors. This would obviate the need to make any position adjustments. This option would limit the object length to 32 meters.

Link to comment
Share on other sites

I actually do that whenever I can, it's extremely useful for indirectly optimizing scripts.

However, sometimes path cuts are not an option, for example when trying to rotate flexi prims at the base. (Flexi cannot be sliced from beginning/end.) This is actually one of the cases I'm dealing with.

Link to comment
Share on other sites

I'm not quite clear about what you are trying to do, but it looks like a basic door script for an uncut prim door.  Something like this ...

rotation adjust;vector offset;default{    state_entry()    {        adjust = llEuler2Rot(<0.0,-90.0,0.0>*DEG_TO_RAD);        vector Size = llList2Vector(llGetLinkPrimitiveParams(2,[PRIM_SIZE]),0);        offset = <-(1.0-llCos(llRot2Angle(adjust)))*0.5*Size.x,0.0,-llSin(llRot2Angle(adjust))*0.5*Size.x>;    }            touch_start(integer total_number)    {        if (llDetectedLinkNumber(0) == 2)        {            list temp = llGetLinkPrimitiveParams(2,[PRIM_POS_LOCAL,PRIM_ROT_LOCAL]);            vector Lpos = llList2Vector(temp,0);            rotation Lrot = llList2Rot(temp,1);            adjust = ZERO_ROTATION/adjust;            llSetLinkPrimitiveParamsFast(2,[PRIM_POS_LOCAL, Lpos + (offset = -offset), PRIM_ROT_LOCAL,adjust*Lrot]);        }    }}

That really is a door script, so it's written to make a simple 90 degree rotation and then back again.  It would be a fairly easy matter to put that stuff from the state_entry event into a user defined function and then trigger it with a timer to make repeated small changes in the adjust variable and anything else that you want to modify..  Ubless I am missing your question.....

 

 

Link to comment
Share on other sites

I guess you can think of it exactly like a door script for uncut prims like you said, the differences being that the "door" is more like a pole that can change its length and the hinge is at one end of the pole.

But I'm having trouble following the script you posted, mainly in state_entry where you assign the offset for the first time.

Link to comment
Share on other sites


Wulfie Reanimator wrote:

I guess you can think of it exactly like a door script for uncut prims like you said, the differences being that the "door" is more like a pole that can change its length and the hinge is at one end of the pole.

[ .... ]

Exactly.  That's why you have to offset the rotation point from the center of the "door" to one end before you rotate it.  Now, if you want to change its length, you're going to have to do it in increments as you make incremental rotations.


[ .... ] But I'm having trouble following the script you posted, mainly in state_entry where you assign the offset for the first time.

You're going to have to draw yourself a picture and do the trigonometry, I'm afraid.  Fortunately, it's not hard. Your "door" is a rectangle, so it has right angles at its corners. When you rotate it through an angle, though, it looks as if you have temporarily twisted the door into a parallelogram.  The angle is a measure of that slight distortion, so you are calculating the "extra" bit of  length that results from it.

 

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 2062 days.

Please take a moment to consider if this thread is worth bumping.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...