Sketchup红宝石平移,旋转,缩放

时间:2017-01-18 14:31:42

标签: ruby math graphics 3d sketchup

我正在开发插件以加载多个boject来建模和执行多个转换 我工作差不多一个星期我通过sketchucation,sketchup ruby​​文档,转换矩阵主题等,我无法弄清楚我做错了什么。 我100%肯定scalling和翻译工作,但我不知道旋转是什么,basiaclly我想围绕轴旋转给定对象。 我真的很感激任何一种专业的红宝石插件制造商帮助! 我的目标是实现这样的组件: enter image description here

但我目前的结果是:

result

我的代码在这里,我知道它不是最短的:

#1)Scale
    scale_transformation = Geom::Transformation.scaling(@transform.scale_vector[0], 
                                                        @transform.scale_vector[1], 
                                                        @transform.scale_vector[2])                                                                                                                                            
    #2)Rotate 
    vector = Geom::Vector3d.new(1, 0, 0)#x axis
    rotate_transformation_x = Geom::Transformation.rotation(@transform.transformation.origin, vector, @transform.rotation_vector[0].degrees)#degrees->radians
    vector = Geom::Vector3d.new(0, 1, 0)#y axis
    rotate_transformation_y = Geom::Transformation.rotation(@transform.transformation.origin, vector, @transform.rotation_vector[1].degrees)#degrees->radians
    vector = Geom::Vector3d.new(0, 0, 1)#z axis
    rotate_transformation_z = Geom::Transformation.rotation(@transform.transformation.origin, vector, @transform.rotation_vector[2].degrees)#degrees->radians

    #if rotate is [0, 0, 0] than rotate transformation is identity matrix:
    if(@transform.rotation_vector[0] == 0 )
        rotate_transformation_x = Geom::Transformation.new()
    end
    if(@transform.rotation_vector[1] == 0 )
        rotate_transformation_y = Geom::Transformation.new()
    end
    if(@transform.rotation_vector[2] == 0 ) 
        rotate_transformation_z = Geom::Transformation.new()
    end
    rotate_transformation = rotate_transformation_x * rotate_transformation_y * rotate_transformation_z

    #3)Translate        
    translate_transformation = Geom::Transformation.translation(Geom::Vector3d.new(
                                                                            meters_to_inches(@transform.translation_vector[0]),
                                                                            meters_to_inches(@transform.translation_vector[1]),
                                                                            meters_to_inches(@transform.translation_vector[2])
                                                                            ))
    #if translate is [0, 0, 0] than translate transformation is identity matrix:
    if(@transform.translation_vector[0] == 0 && @transform.translation_vector[1] == 0 && @transform.translation_vector[2] == 0 )
        translate_transformation = Geom::Transformation.new()
    end
    #using overloaded operator '*' for matrixes

    puts @path + "\r\nFROM PARENT : " + @transform.to_s + ", matrix = " + @transform.transformation.to_a.each_slice(4).inject { |str, row| "#{str}\r\n#{row}" }
    @transform.transformation = (translate_transformation * rotate_transformation * scale_transformation) * @transform.transformation

@ transform.transformation如果没有先前的转换是单位矩阵。 我认为我的错误可以与乘法矩阵的顺序联系起来 感谢您提供任何帮助!!!

旋转和翻译定义如下(例如): enter image description here

0 个答案:

没有答案
相关问题