by dacastror » Mon Jun 25, 2012 5:37 am
Hi, I'm trying to print a transformation matrix, I tried the following:
pointdd = Geom::Point3d.new 11,22,33 tdd = Geom::Transformation.new pointdd a = tdd.to_a text="-------------------------------------------------------\n" 4.times do |b| 4.times do |e| if ((e+1)%4==0) text << a[e*4+b].to_s+"\n" else text << a[e*4+b].to_s+" "+" "+" "+" "+" "+" "+" "+" "+" "+" " end end end text<<"------------------------------------------------------\n" UI.messagebox( text, MB_MULTILINE)
I wanted to hear suggestions of more elegant ways to do this. (I wrote several times +" " for failure to escrbir several spaces followed here)
thank you for your attention.
Last edited by thomthom on Mon Jun 25, 2012 8:50 am, edited 1 time in total.
Reason: Tagged the thread with [Code]
-
dacastror
-
- Posts: 138
- Joined: Mon Jun 14, 2010 12:25 am
- Name: Diego Castro
by danielbowring » Mon Jun 25, 2012 6:42 am
- Code: Select all
def inspect_transformation(t) ta = t.to_a return (0...4).collect() {|i| ta[i*4, 4].join(', ') }.join("\n") end
- Code: Select all
>>> point = Geom::Point3d.new 11,22,33 >>> tdd = Geom::Transformation.new pointdd >>> puts inspect_transformation(tdd) 1.0, 0.0, 0.0, 0.0 0.0, 1.0, 0.0, 0.0 0.0, 0.0, 1.0, 0.0 11.0, 22.0, 33.0, 1.0
Edit: And if you like things to line up: - Code: Select all
def inspect_transformation_adv(t, args={}) format = "%.#{args[:places] || 3}f" ta = t.to_a.map() {|i| format%[i] } maxlength = ta.max() {|i, j| i.length <=> j.length }.length ta = ta.map() {|i| i.ljust(maxlength) } return (0...4).collect() {|i| ta[i*4, 4].join(args[:separator] || ', ') }.join("\n") end
- Code: Select all
>>> point = Geom::Point3d.new 11,22,33 >>> tdd = Geom::Transformation.new pointdd >>> puts inspect_transformation_adv(tdd) 1.000 , 0.000 , 0.000 , 0.000 0.000 , 1.000 , 0.000 , 0.000 0.000 , 0.000 , 1.000 , 0.000 11.000, 22.000, 33.000, 1.000
Edit: although that's not the orientation you use
Last edited by danielbowring on Mon Jun 25, 2012 7:19 am, edited 1 time in total.
-

danielbowring
-
- Posts: 67
- Joined: Mon Aug 29, 2011 8:15 am
- Name: DanielBowring
by danielbowring » Mon Jun 25, 2012 7:17 am
Here's one in your format, although you should probably use one of the ones above (More info here) - Code: Select all
def inspect_transformation_adv(t, args={}) format = "%.#{args[:places] || 3}f" ta = t.to_a.map() {|i| format%[i] } maxlength = ta.max() {|i, j| i.length <=> j.length }.length ta = ta.map() {|i| i.ljust(maxlength) } return (0...4).map() {|i| (0...4).map() {|j| ta[j*4+i] }.join(args[:separator] || ', ') }.join("\n") end
- Code: Select all
>>> point = Geom::Point3d.new 11,22,33 >>> tdd = Geom::Transformation.new pointdd >>> puts inspect_transformation_adv(tdd) 1.000 , 0.000 , 0.000 , 11.000 0.000 , 1.000 , 0.000 , 22.000 0.000 , 0.000 , 1.000 , 33.000 0.000 , 0.000 , 0.000 , 1.000 >>> puts inspect_transformation_adv(t, {:separator => ' '}) 1.000 0.000 0.000 11.000 0.000 1.000 0.000 22.000 0.000 0.000 1.000 33.000 0.000 0.000 0.000 1.000
-

danielbowring
-
- Posts: 67
- Joined: Mon Aug 29, 2011 8:15 am
- Name: DanielBowring
by thomthom » Mon Jun 25, 2012 8:44 am
Is it to visually inspect the matrix of entities, if so you can use this tool: viewtopic.php?t=44859
-

thomthom
- PluginStore Author

-
- Posts: 19457
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: Thomas Thomassen
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: other
- Level of SketchUp: Advanced
-
by Dan Rathbun » Mon Jun 25, 2012 8:45 am
Here's my simple brute force method: - Code: Select all
def trans_matrix_text( gt )
return "Not a trnasformation object!" unless gt.is_a?(Geom::Transformation) a = gt.to_a w = 3 # width a.each{|n| s = n.to_s.size; w = s if s>w } l = (w*4)+3 # create a line output format string: fmt = " | %#{w}s %#{w}s %#{w}s %#{w}s |\n" text = "\n" text << (32.chr*2)<<151.chr<<151.chr<<(32.chr*l)<<151.chr<<151.chr<<"\n" text << fmt % [ a[0].to_s, a[1].to_s, a[2].to_s, a[3].to_s ] text << fmt % [ a[4].to_s, a[5].to_s, a[6].to_s, a[7].to_s ] text << fmt % [ a[8].to_s, a[9].to_s, a[10].to_s, a[11].to_s ] text << fmt % [ a[12].to_s, a[13].to_s, a[14].to_s, a[15].to_s ] text << (32.chr*2)<<151.chr<<151.chr<<(32.chr*l)<<151.chr<<151.chr<<"\n" return text
end # def
pt = Geom::Point3d.new( 11,22,33 ) text = trans_matrix_text( Geom::Transformation.new(pt) ) UI.messagebox( text, MB_MULTILINE, "Tranformation Matrix" )
I have tweaked my system by copying Consolas font to the font used by dialogs, so I have monospaced text output. (It was easier than tweaking the resources in the executable after each update.) trans_matrix_MB.png trans_matrix_IO.png 
I'm not here much anymore. But a PM will fire email notifications.
-

Dan Rathbun
- PluginStore Author

-
- Posts: 5056
- Joined: Tue Oct 06, 2009 3:06 am
- Location: Florida, USA
- Name: Dan Rathbun
- Operating system: Windows
- SketchUp version: 2015
- License type: Pro
- SketchUp use: education
- Level of SketchUp: Advanced
by dacastror » Tue Jun 26, 2012 4:00 am
Thanks for responding, I have helped a lot. me a question arises about the transformations. if I need to apply a transformation to an object but not in the principal coordinate axes, but the coordinate axes of a group (rotated) what should I use? (sorry for my bad English)
-
dacastror
-
- Posts: 138
- Joined: Mon Jun 14, 2010 12:25 am
- Name: Diego Castro
by thomthom » Tue Jun 26, 2012 8:26 am
You mean, transform an object around its own axis and not world axis?
-

thomthom
- PluginStore Author

-
- Posts: 19457
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: Thomas Thomassen
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: other
- Level of SketchUp: Advanced
-
by dacastror » Wed Jun 27, 2012 5:47 pm
thomthom wrote:You mean, transform an object around its own axis and not world axis?
yes, exactly
-
dacastror
-
- Posts: 138
- Joined: Mon Jun 14, 2010 12:25 am
- Name: Diego Castro
by thomthom » Wed Jun 27, 2012 8:02 pm
Create a local transformation and apply with with .transform!( tramsformation ) instead of setting the .transformation matrix manually. Or am I missing something?
-

thomthom
- PluginStore Author

-
- Posts: 19457
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: Thomas Thomassen
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: other
- Level of SketchUp: Advanced
-
by dacastror » Thu Jun 28, 2012 7:15 pm
thomthom wrote:Create a local transformation and apply with with .transform!( tramsformation ) instead of setting the .transformation matrix manually. Or am I missing something?
How to create a local transformation? I would like to see some sample piece of code to guide me
-
dacastror
-
- Posts: 138
- Joined: Mon Jun 14, 2010 12:25 am
- Name: Diego Castro
by dacastror » Thu Jun 28, 2012 7:37 pm
I wonder if there is any way to know the orientation of a group with respect to the axis of the world
-
dacastror
-
- Posts: 138
- Joined: Mon Jun 14, 2010 12:25 am
- Name: Diego Castro
by TIG » Thu Jun 28, 2012 7:44 pm
You have the model's axes from X_AXIS etc and ORIGIN. Then you have group.transformation.axes or group.transformation.xaxis etc... and group.transformation.origin too... So you can find the relative locations [which are points3ds] and angles between axes [which are vector3ds] - see the methods for those types...
TIG
-

TIG
- Global Moderator
-
- Posts: 20429
- Joined: Mon Nov 12, 2007 7:24 pm
- Location: Northumbria UK
- Name: TIG
- Operating system: Windows
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
by thomthom » Thu Jun 28, 2012 8:16 pm
dacastror wrote:thomthom wrote:Create a local transformation and apply with with .transform!( tramsformation ) instead of setting the .transformation matrix manually. Or am I missing something?
How to create a local transformation? I would like to see some sample piece of code to guide me
- Code: Select all
point = instance.transformation.origin vector = instance.transformation.yaxis rotation = Geom::Transformation.rotation( point, vector, 30.degrees ) instance.transform!( rotation )
-

thomthom
- PluginStore Author

-
- Posts: 19457
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: Thomas Thomassen
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: other
- Level of SketchUp: Advanced
-
by dacastror » Thu Jun 28, 2012 9:11 pm
thank you very much Thomas and Tig that prompt reply! I will try to implement your suggestions right now
-
dacastror
-
- Posts: 138
- Joined: Mon Jun 14, 2010 12:25 am
- Name: Diego Castro
by Ad Machine » 5 minutes ago
-
Ad Machine
- Robot
-
- Posts: 2012
-
Return to Developers' Forum
|