Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby Sketchup红宝石平移、旋转、缩放_Ruby_Math_Graphics_3d_Sketchup - Fatal编程技术网

Ruby Sketchup红宝石平移、旋转、缩放

Ruby Sketchup红宝石平移、旋转、缩放,ruby,math,graphics,3d,sketchup,Ruby,Math,Graphics,3d,Sketchup,我正在开发插件,将多个对象加载到模型中并执行多个转换 我工作了将近一个星期,我经历了sketchucation、sketchup ruby文档、转换矩阵等主题,但我不知道我做错了什么。 我100%确信缩放和平移是有效的,但我不知道旋转是什么,基本上我想绕轴旋转给定的对象。 我非常感谢任何专业ruby插件制造商的帮助!!! 我的目标是实现以下目标: 但我目前的结果是: 我的代码在这里,我知道它不是最短的: #1)Scale scale_transformation = Geom::Tr

我正在开发插件,将多个对象加载到模型中并执行多个转换 我工作了将近一个星期,我经历了sketchucation、sketchup ruby文档、转换矩阵等主题,但我不知道我做错了什么。 我100%确信缩放和平移是有效的,但我不知道旋转是什么,基本上我想绕轴旋转给定的对象。 我非常感谢任何专业ruby插件制造商的帮助!!! 我的目标是实现以下目标:

但我目前的结果是:

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

#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如果之前没有转换,则为单位矩阵。 我认为我的错误可能与矩阵的乘法顺序有关 谢谢你的帮助

旋转和平移定义如下(例如):

问题出在哪里还不清楚。你能给出一个简单物体的例子,一个旋转定义,你期望得到什么?完整的Ruby代码对于测试它也很有帮助。我添加了示例转换定义,对象由组件树描述,每个子级都从父级继承转换,我认为我很接近,但我不知道我的旋转是否正常;/,,我期待上面显示的结果图片,我得到了一些非常接近的结果…你想做什么?开始转换前的设置是什么?你能提供一个自给自足的剪报吗?当前一个包含许多未定义的变量,因此我们很难准确猜测它们是什么。您提到“我想绕轴旋转给定对象”-我们可以集中精力吗?什么轴心?什么东西?