[Request] Transformation rotation for animation help

[Request] Transformation rotation for animation help

Postby chrisglasier » Wed Feb 25, 2009 8:31 am

Here is a clip of a web dialog being used as a kind of ruby console but for Javascript.

The report comes from this ruby callback:
Code: Select all

@dlg.add_action_callback("modelArrayGenerate") {|d, p|
     
a = 0

model = Sketchup.active_model
model.options["UnitsOptions"]["SuppressUnitsDisplay"]= true
entities = model.active_entities
selection = model.selection[0]

entities.each do |entity|
if entity.class == Sketchup::Group || entity.class == Sketchup::ComponentInstance

if entity == selection
t = selection.transformation
to = t.origin

array = []
array[0] = ["Index",a]
array[1] = ["x",to[0]]
array[2] = ["y",to[1]]
array[3] = ["z",to[2]]
array[4] = ["axisX",t.xaxis]
array[5] = ["axisY",t.yaxis]
array[6] = ["axisZ",t.zaxis]

array = array.join(";")

cmd = "receiveArray('#{array}');"
@dlg.execute_script (cmd)

end #selection if

end   #entity if
a+=1
end  # loop 
}


I want to save each of the transformation reports to record various positions and orientations for a component manipulation in the SU display. These are to be used to animate the component directly from the web dialog scripts. As you can work SU tools while web dialog animation is running, I want to test whether it is possible to have components flying around while regular scene-based animation is in progress.

If anyone would like to help with that that would be great, but my first ambition is to get to grips with or solve the rotation business - I am currently really confused. Can anyone help me to translate the x-, y- and zaxis results to degrees for each axis?

Many thanks

Chris
0
Last edited by chrisglasier on Wed Feb 25, 2009 10:22 am, edited 1 time in total.
With JSON machines we can analyse what is to be achieved so that IT can help with automation to achieve it.
User avatar
chrisglasier 
PluginStore Author
PluginStore Author
 

Re: [Request] Transformation rotation for animation help

Postby tomasz » Wed Feb 25, 2009 9:44 am

chrisglasier wrote:Can anyone help me to translate the x-, y- and zaxis results to degrees for each axis?

Have you tried .degrees method? Is it something more complicated?

Tomasz
0

tomasz 
SU2TH & SU2KT Developer
 

Re: [Request] Transformation rotation for animation help

Postby chrisglasier » Wed Feb 25, 2009 10:14 am

Tomasz wrote:Have you tried .degrees method? Is it something more complicated?


I have used the degrees method when there is an Integer to attach it to, but here there are three numbers for each axis. For me it is more complicated because I don't really know what's what!

Chris
0
With JSON machines we can analyse what is to be achieved so that IT can help with automation to achieve it.
User avatar
chrisglasier 
PluginStore Author
PluginStore Author
 

Re: [Request] Transformation rotation for animation help

Postby tomasz » Thu Feb 26, 2009 10:15 am

I have done a search, because I have remembered it has been discussed already.
The Transformation Matrix thread.

There is enough information there with examples of angles readouts.

Good luck
Tomasz
0

tomasz 
SU2TH & SU2KT Developer
 

Re: [Request] Transformation rotation for animation help

Postby chrisglasier » Thu Feb 26, 2009 10:29 am

Tomasz wrote:There is enough information there with examples of angles readouts.


Thanks very much Tomasz for that. I don't know how I missed it; I am always looking out for such topics.

I decided to understand a bit more and am currently studying Vector lessons.

So between the two I should get to where I want - the ability to interpret any skp model as a javascript array. My idea is to kind of sneak up on namesets from the rear, as opposed to previous full frontal assault!

Cheers

Chris
0
With JSON machines we can analyse what is to be achieved so that IT can help with automation to achieve it.
User avatar
chrisglasier 
PluginStore Author
PluginStore Author
 

Re: [Request] Transformation rotation for animation help

Postby tomasz » Thu Feb 26, 2009 10:56 am

chrisglasier wrote:My idea is to kind of sneak up on namesets from the rear, as opposed to previous full frontal assault!

:D :thumb:
0

tomasz 
SU2TH & SU2KT Developer
 

Re: [Request] Transformation rotation for animation help

Postby Jim » Thu Feb 26, 2009 11:59 am

chrisglasier wrote:Can anyone help me to translate the x-, y- and zaxis results to degrees for each axis?


Vector3d.angle_between will get you part of the way there.

Code: Select all
angle = t.zaxis.angle_between(Z_AXIS).degrees


However, angle_between always gives a result between 0 and 180 (or more accurately between zero and π).
0
Hi

Jim 
Global Moderator
 

Re: [Request] Transformation rotation for animation help

Postby thomthom » Thu Feb 26, 2009 12:25 pm

Jim wrote:
Code: Select all
angle = t.zaxis.angle_between(Z_AXIS).degrees

However, angle_between always gives a result between 0 and 180 (or more accurately between zero and π).

What..?! All you need to do to convert radians to degrees is appending .degrees? :o doh! :oops:
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: [Request] Transformation rotation for animation help

Postby Jim » Thu Feb 26, 2009 12:31 pm

thomthom wrote:What..?! All you need to do to convert radians to degrees is appending .degrees? :o doh! :oops:


Heh, see the Numeric documentation for the SketchUp-specific additions.
0
Hi

Jim 
Global Moderator
 

Re: [Request] Transformation rotation for animation help

Postby thomthom » Thu Feb 26, 2009 12:34 pm

Jim wrote:
thomthom wrote:What..?! All you need to do to convert radians to degrees is appending .degrees? :o doh! :oops:


Heh, see the Numeric documentation for the SketchUp-specific additions.

Meh,... I've seen that page, taking note of the unit conversion, but completely missed the ones relating to radians and degrees. *goes of to clean up some scripts...*
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: [Request] Transformation rotation for animation help

Postby chrisglasier » Thu Feb 26, 2009 12:46 pm

Jim wrote:
Code: Select all
angle = t.zaxis.angle_between(Z_AXIS).degrees

However, angle_between always gives a result between 0 and 180 (or more accurately between zero and π).


A quick pre-dinner try I get this with 90 deg rotation around X :

Transformation report2.jpg


Now off to eat!

Chris
0
With JSON machines we can analyse what is to be achieved so that IT can help with automation to achieve it.
User avatar
chrisglasier 
PluginStore Author
PluginStore Author
 

Re: [Request] Transformation rotation for animation help

Postby chrisglasier » Fri Feb 27, 2009 4:05 am

chrisglasier wrote:
Jim wrote:
Code: Select all
angle = t.zaxis.angle_between(Z_AXIS).degrees

However, angle_between always gives a result between 0 and 180 (or more accurately between zero and π).


A quick pre-dinner try ...


... failed because I made
t = selection.transformation, when it should be something related to vector3D ??
Also I don't understand the difference/relationship/source of zaxis and (Z_AXIS).

Perhaps I have made it too confusing both here and also in this previous topic.

All I want to do is iterate through model entities to make each component and group a javascript array element, each with its own array of name/value couplets at least for xPos, yPos, zPos, xRot, yRot, zRot. The xyz business seems OK, where in an animation, for example, I can compare one entity's position with a new position to determine the translation. I want to do the same with rotations around each of the axes.

Sorry if I'm being rather painful, but I am sure a good result will help the mantra below.

Chris
0
With JSON machines we can analyse what is to be achieved so that IT can help with automation to achieve it.
User avatar
chrisglasier 
PluginStore Author
PluginStore Author
 

Re: [Request] Transformation rotation for animation help

Postby Jim » Fri Feb 27, 2009 4:18 am

Chris,

Z_AXIS, X_AXIS, and Y_AXIS are constants that are the vectors of SketchUp's global axes.

Here's a screenshot of a cube rotated 45 deg around the Z axis.

And I just noticed I said to use .degrees in an earlier post, sorry; it's .radians.
0
Hi

Jim 
Global Moderator
 

Re: [Request] Transformation rotation for animation help

Postby chrisglasier » Fri Feb 27, 2009 4:45 am

Jim wrote:Chris,

Z_AXIS, X_AXIS, and Y_AXIS are constants that are the vectors of SketchUp's global axes.

Here's a screenshot of a cube rotated 45 deg around the Z axis.

And I just noticed I said to use .degrees in an earlier post, sorry; it's .radians.


Jim I think the fog maybe clearing ... many thanks ... chris
0
With JSON machines we can analyse what is to be achieved so that IT can help with automation to achieve it.
User avatar
chrisglasier 
PluginStore Author
PluginStore Author
 

Re: [Request] Transformation rotation for animation help

Postby chrisglasier » Sat Feb 28, 2009 10:54 am

I made a skp, rb, html set to test what I understand so far about transformations on a 3x4x5 metre group. If you want to try it out temporarily unzip the files to your plugin directory.

transformations.zip


Here is a clip of it showing a group rotating around each of the axes in turn:



The rotations are made with:

tr = Geom::Transformation.rotation(Geom::Point3d.new(ent.bounds.center), rv, theDegrees), where rv is the axis,

and the angle_between values with:

(t.xaxis.angle_between X_AXIS).radians
+ same for y and z.

From this, I gather if the angle_between values returned are 0-180-180, the group has been turned by 180 deg on the X_AXIS; and if 0_90_90, the group could have been turned 90 or 270 (-90) degs on the X_AXIS; and the same for the angle_between values for the other axis rotations.

The second clip shows the application of different series of rotations:



Screenshots of rotations providing angle_between values of 90-90-90 shows there is either something fundamental missing or perhaps that an entirely different method is appropriate.

angle_between 90 90 90.jpg


Any suggestions about this most welcome...

Chris
0
With JSON machines we can analyse what is to be achieved so that IT can help with automation to achieve it.
User avatar
chrisglasier 
PluginStore Author
PluginStore Author
 

SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago



Ad Machine 
Robot
 



 

Return to Plugins

Who is online

Users browsing this forum: claudeh35, Dalia Markuz , mlydo, rml and 16 guests

Visit our sponsors: