Rotation on 2 axis doesn't give expected result

Started by altair, March 05, 2014, 01:43:26 PM

Previous topic - Next topic

0 Members and 0 Guests are viewing this topic.

prl

#60
And now to bring this topic back to DesignCAD and how great this program is (and was), think about how the drag copy/move command works in 3d when you set three handles points.


The first point anchors the object in 3d space.

The second point defines the direction in 3d space.

The third point defines the plane (the roll about the first two points).

Brilliant, and this is from 25 years ago!!  And the program does it graphically with a ghost outline while you are doing the transformation matrix.  Can we say more. 

(And now for a time after time music break, thanks Sam)

prl

#61
Quote from: samdavo on March 09, 2014, 03:30:04 AM
Suppose there is a roll of 12 degrees and a pitch of 6 degrees.
How do you combine these?

I would guess for objects (ships or aircraft, etc.), direction and pitch are global and roll is local.  DesignCAD's handles does it this way.  Position and direction vector which includes pitch being defined by the first two points (global), the last point defining the spin position (local roll) of the mathematical plane about the direction vector.  The order of operations is a convention and can be changed but the relationship to global or local axes is fixed.

prl

#62
We're having fun with this one, no?

altair

This explanation should be part of the manual.  Like many of the things I've found on this forum.

I'm having a lot of fun in my learning process, and now I'm way past the point where my most useful button was the Delete key... ;)


prl

#64
Quote from: samdavo on March 09, 2014, 03:30:04 AM
I get different final positions in space (?)  Hope I'm correct, but I have gotten the same result twice, so I think I must be right.

Sam, I've attempted to take your experiment one step further.  I introduced an initial 20 degree yaw.  Unless I screwed up the rotations, I believe the order isn't important but keeping track of your local and global axis before you do the rotation is.  Also I reversed your -12 degrees rotation to +12 degrees for the graphics.

And to be clear.

1.  The initial 20 degree yaw means the solid is rotated 20 degrees about the global Y axis but the local xyz axis is pointing in the same direction as global XYZ. (Think of an aircraft flying forward in a crosswind.)
2.  The 6 degree pitch means a 6 degree rotation about the global Z axis
3.  The 12 degree roll means a 12 degree rotation about the local model x axis.

When you are doing the rotations, you need to take along the model xyz system shown as the xzy triad at the centroid of the solid.

Also the way to read the graphic is you start with the lowest model (the at rest model) and you do the rotation operations vertically.

And what you are seeing in the graphic is the result of the operation.  So where is says local, you take the model shown below it, copy it up and set the local axis to the triad position, and then do the indicated 12 degree roll about the model x axis.  It can get confusing.

Edit:  I added a second graphic.  The XYZ is the global orientation, the xyz the model.



prl

Referring to my above post, I was wondering about other combinations.  As long as you do the global Y rotation first, the other two seem to give you the same positioning.  But if you don't start with the global Y, you will not end up in the same position.

So I think I'm wrong about the order not mattering.   Maybe someone else can double-check this.









prl

Well I'm in gnawing mode . . .

Here are the combinations I've looked at with the following understanding (refer to the previous graphics if you want to repeat these results).

1.  Global y rotation of 20
2.  Global z rotation of 6
3.  Local x rotation of 12


Combination of sequential rotations.

1 2 3 is the same as 1 3 2  (that's what the above graphics attempt to show)

but
1 2 3 is NOT the same as 2 1 3
1 2 3 is NOT the same as 2 3 1

but
1 2 3 is the same as 3 1 2

but
1 2 3 is NOT the same as 3 2 1


samdavo

#67
prl,
THis arguably all started with your "xyzhere.d3m" macro lol.

But it is just so counter-intuitive.  In short, working even with local axes, one gets a different result if you roll then pitch, as if you pitch then roll  (starting to sound like Jailhouse Rock now).

Note that I have used your "xyzhere" for the rotation about local axes, and, as you say, carried the "tricolour" axes along with me.   When I want to rotate about a local axis, I "rotate about a line" and click the end of the arrow in question.

Note that I have amended your macro slightly (xyzhere2.d3m)  to the extent that I have separated the end of the arrow from the text ( X, Y or Z as applic),  i.e. pointxyz [x+1.1*d,y,z]
PS that is sure a handy macro - cheers

Quote>Text2d
{
  <Color [sys(334), sys(335), sys(336)]
  <pointxyz [x+1.1*d,y,z]
  <Style 0
  <Justification 0
  <Angle 0
  <Text "x"

'Program: xyzhere2.d3m
'edit 20130310  small gap between end of arrow and text eg X Y or Z i.e. text at 1.1d

sf = .25 'scale factor for arrow and text size. Fiddle with this to your liking

'save various settings
cl = sys(3) 'current layer
ts = sys(12) ' current text size
cred = sys(300) 'current red value
cgrn = sys(301) 'current green value
cbl = sys(302) 'current blue
cctf = sys(254) 'current color text flag
ccfl = sys(255) 'current color layer flag
pspm = sys(1116) 'preset point mode'

sys(1116)=0 'preset point mode off for sphere rubberband
sys(41) = 18 'sphere rubberband
sys(36)=0

SetPoint "Set 1st point xyz symbol center,  2nd point for xyz symbol size", 2
pointval x,y,z, 1 'store first point only

sys(36)=2 'hide the dialogs
>sphere
{
  <Latitude 5
  <Longitude 5
  <Orientation 0
  <UsePresetPoints
}

entity sys(9) 'get coordinates of sphere just drawn
pointval cx,cy,cz, 1
pointval ex2,ey2,ez2, 3
sys(1)=0

dx = ex2 - cx
dy = ey2 - cy
dz = ez2 - cz
d = dx * dx + dy * dy + dz * dz

if d = 0 then goto restore
d = sqrt(d)
sys(12) = sf*d

as = sys(12)

>eraselast
{
}

sys(3)=999 'switch to empty/junk layer, say 999'
sys(254) = 1 'turn on
sys(255) = 1 'turn on

sp1 = sys(9)+1
>arrow
{
  <Color [sys(334), sys(335), sys(336)]
  <Type 4
  <Size [as]
  <pointxyz [x,y,z]
  <pointxyz [x+d,y,z]
  <Doublesided 0
}

>Text2d
{
  <Color [sys(334), sys(335), sys(336)]
  <pointxyz [x+1.1*d,y,z]
  <Style 0
  <Justification 0
  <Angle 0
  <Text "x"
}

>arrow
{
  <Color [sys(337), sys(338), sys(339)]
  <Type 4
  <Size [as]
  <pointxyz [x,y,z]
  <pointxyz [x,y+d,z]
  <Doublesided 0
}

>Text2d
{
  <Color [sys(337), sys(338), sys(339)]
  <pointxyz [x,y+1.1*d,z]
  <Style 0
  <Justification 0
  <Angle 0
  <Text "y"
}

>arrow
{
  <Color [sys(340), sys(341), sys(342)]
  <Type 4
  <Size [as]
  <pointxyz [x,y,z]
  <pointxyz [x,y,z+d]
  <Doublesided 0
}

>Text2d
{
  <Color [sys(340), sys(341), sys(342)]
  <pointxyz [x,y,z+1.1*d]
  <Style 0
  <Justification 0
  <Angle 0
  <Text "z"
}

for j = sp1 to sys(9) 
  getattr j, type, select
  putattr j, type, 1
next j
>groupdefine
{
}

gosub restore



regen
end

'subroutines follow

restore: 'restore settings
sys(36)=0
sys(80) = 0
sys(3)= cl
sys(12) = ts
sys(41)=0
sys(1116)=pspm
sys(300)=cred
sys(301)=cgrn
sys(302)=cbl
sys(254)=cctf
sys(255)=cclf
return


edit : I note, when you superimpose the results of pitch then roll vs roll then pitch, that a "yaw" of about 1,3 degrees has crept in.    Now to state the obvious, I am sure many here are saying "yawn more like it !!" lol.

To which I would respond as I always do by trying to think of something interesting about a yawn.  And here it is.   I read recently that ... you can tell how bonded you are with your dog, if you yawn in front of it, and the dog yawns a sympathy yawn.  So I tried it with my dog - anda the best I can get is that she licks here lips a bit :)

Mind you lol, if I yawn in front of the wife, she ALWAYS gives me back a sympathy yawn.   That;s how I know we are so well bonded !! lol.

prl

#68
Quote from: samdavo on March 09, 2014, 01:22:48 PM
When I want to rotate about a local axis, I "rotate about a line" and click the end of the arrow in question.

Sam, try the same experiment but set a temporary work plane rather than rotating about a line.  For the work plane, the new origin is the triad origin, the new x is the end of the red arrow, the new y is the end of the blue arrow.  Then you do a rotate about the x axis by 12 degrees (it is now a true local x axis).   As I tried now several times, steps 1 2 3 for me equal steps 1 3 2


samdavo

#69
prl, ok - personally I think "rotate about a line" is foolproof.  (even your arrows seem to work :) )
(just that the introduction of a yaw was counter-intuitive, hence not feelproof :) )

And when I think about it some more, I can imagine that
a) pitch followed by roll (local axes) with not change your direction (heading / bearing / hence yaw)
b) but that roll followed by pitch WILL change your direction  (hence yaw)

Taking it to "Lar's shoe extreme"  (and still using local axes, whether of not an "old salt" would agree with that definition) ... 
a) pitch of 90 followed by roll of 90 has you heading vertically down (or up)
b) roll of 90 followed by pitch of 90 has you heading due west (or maybe east) compared to your original heading, assumed to be north.

prl

#70
Quote from: samdavo on March 09, 2014, 02:01:56 PM
prl, ok - personally I think "rotate about a line" is foolproof.  (even your arrows seem to work :) )

One of us is doing things differently.  I'll see if I can track down the difference (for the 1 2 3 versus 1 3 2) case or the error in my methods.  No arguments about some of the other combos.

prl

#71
Sam,

Run the following step by step macro. Do it in an empty drawing in 3d mode.  Also you can look over the code.  One of us isn't doing something.  This way you can read what I'm thinking and either confirm or point out my mental block. 

'Program 123.d3m

precision 15

sys(541) = 0 'color by layer OFF

'draw the 1st framing square in BLUE
>line
{
<color 0,0,255
<pointxyz [10, 0, 0]
<pointxyz [0, 0, 0]
<pointxyz [0, 5, 0]
}
>fittowindow
{
}

message "Press any key to do a global rotate about y by 20 degrees"
>pointselect
{
<Type 0
<pointxyz [0, 0, 0]
}

>Rotate
  {
  <Axis 1
  <Angle 20
  <ThroughHandle 1
  <DragMode 0
}
sys(80)=0
>fittowindow
{
}

message "Press any key to do a global rotate about z by 6 degrees"
>pointselect
{
<Type 0
<pointxyz [0, 0, 0]
}

>Rotate
  {
  <Axis 2
  <Angle 6
  <ThroughHandle 1
  <DragMode 0
}
sys(80)=0
>fittowindow
{
}

message "Press any key set a local axis work plane"

'get the points of the line

entity sys(9)
pointval xh, yh, zh, 1
pointval xo, yo, zo, 2
pointval xv, yv, zv, 3
sys(1)=0

>Workplane
    {
    <Name "temp"
    <pointxyz [xo, yo, zo)]
    <pointxyz [xh, yh, zh]
    <pointxyz [xv, yv, zv]
    }
>fittowindow
{
}   
   

message "Press any key to do a local rotate about x by 12 degrees"
>pointselect
{
<Type 0
<pointxyz [0, 0, 0]
}

>Rotate
  {
  <Axis 0
  <Angle 12
  <ThroughHandle 1
  <DragMode 0
}
sys(80)=0

>unworkplane
{
}
>pointselect
{
<Type 0
<pointxyz [0, 0, 0]
}

'move it out of the way by one unit in the z direction
>move
   {
   <Reference 0
   <Type 1
   <Pointxyz [0,0,1]
   }

sys(80)=0
>fittowindow
{
}   
'/////////////////////////////////////////////////////////////////////
'end of the first framing square



'/////////////////////////////////////////////////////////////////////
'draw the 2nd framing square in RED
>line
{
<color 255,0,0
<pointxyz [10, 0, 0]
<pointxyz [0, 0, 0]
<pointxyz [0, 5, 0]
}
>fittowindow
{
}

message "For the red framing square, press any key to do a global rotate about y by 20 degrees"
>pointselect
{
<Type 0
<pointxyz [0, 0, 0]
}
>Rotate
  {
  <Axis 1
  <Angle 20
  <ThroughHandle 1
  <DragMode 0
}
sys(80)=0
>fittowindow
{
}

message "Press any key set a local axis work plane"
'get the points of the line

entity sys(9)
pointval xh, yh, zh, 1
pointval xo, yo, zo, 2
pointval xv, yv, zv, 3
sys(1)=0

>Workplane
    {
    <Name "temp"
    <pointxyz [xo, yo, zo)]
    <pointxyz [xh, yh, zh]
    <pointxyz [xv, yv, zv]
    }
>fittowindow
{
}   

message "Press any key to do a local rotate about x by 12 degrees"
>pointselect
{
<Type 0
<pointxyz [0, 0, 0]
}

>Rotate
  {
  <Axis 0
  <Angle 12
  <ThroughHandle 1
  <DragMode 0
}
sys(80)=0

>unworkplane
{
}
>fittowindow
{
}

message "The temporary work plane has been reset, Press any key to do a global rotate about z by 6 degrees"
>pointselect
{
<Type 0
<pointxyz [0, 0, 0]
}

>Rotate
  {
  <Axis 2
  <Angle 6
  <ThroughHandle 1
  <DragMode 0
}
sys(80)=0
>fittowindow
{
}

message "Done.  The two framing squares should be identically positioned in 3d space but offset by 1 unit in the z direction"

END

samdavo

#72
Edit - this post crossed with yours above.  I will check out your macro "later"
Assuming you are snowed in (and not snowed under) -

Just FYI, I repeated the exercise - used "set working plane", clicked OXY (from your tricolour arrows), and then "rotate about (new) Z" or "X" or whatever.

I get a similar if not exactly the same result ( although the slew/yaw is around 1.2521 deg first time,  and around  1.2484 deg using working planes =  second time).   There is every chance I have made a small human error  to explain that 2nd etc decimal point.  [ edit - yep - the right answer is 1.248 deg - picked the wrong points when I came up with 1.2521 ]
cheers

PS I have said before that the yaw was "around 1.3 deg".  That is because the angle I am measuring (edit to be checked) is the true angle between two lines, not the angle seen in plan ( 2 cents)
(Actually I think I know the error that is causing that second decimal point - but that doesn;t change the main point of the exercise.)

prl

#73
Quote from: samdavo on March 09, 2014, 03:31:05 PM
Just FYI, I repeated the exercise - used "set working plane", clicked OXY (from your tricolour arrows), and then "rotate about (new) Z" or "X" or whatever.

Sam, you only use the set work plane with the rotate about x by 12 degrees step and you use the small oxy axis in the model.  All other steps use the default XYZ system.


Edit:  When you run the macro, you'll get two lines in 3d space.  You can pick up the second line and set it on the first.    When you do that you will get


; Data for  2  objects.

;Entity 1 is type 1 (Line) on layer 1
; Name string;
; RGB color is: 255, 0, 0
; Line Type: 0 ; Line Width: 0.000000 ; ; Line Type Scale: 1.000000 .
; Group # 0 ; Solid # 0 ; Points: 3
; Selection Status: 1
; String data: 
     9.345448862876 0.982246255947 3.420201433257
     0.000000000000 0.000000000000 0.000000000000
     -0.157619136032 4.901111117109 -0.976865408183

;Entity 2 is type 1 (Line) on layer 1
; Name string;
; RGB color is: 0, 0, 255
; Line Type: 0 ; Line Width: 0.000000 ; ; Line Type Scale: 1.000000 .
; Group # 0 ; Solid # 0 ; Points: 3
; Selection Status: 3
; String data: 
     9.345448862876 0.982246255947 3.420201433257
     0.000000000000 0.000000000000 0.000000000000
     -0.157619136032 4.901111117109 -0.976865408183

prl

Quote from: samdavo on March 09, 2014, 03:31:05 PM
Assuming you are snowed in (and not snowed under) -

Well today it was warm, about 22 with bright sun.  I decided to clear off the deck.  Out of shape. Needed lots of breaks, hence the posts.