如何获得组的空间坐标?

时间:2019-01-08 22:50:57

标签: ruby coordinates spatial sketchup

在youtube上有一个带有动画的视频,其中一个是在Ruby的Sketchup中录制的。 Here Link

我想做同样的动画,我使用了余弦函数。但不幸的是,我不知道如何获得余弦函数中使用的$grp_main的空间坐标。

以下是我的代码:

$mod = Sketchup.active_model # Open model
$ent = $mod.entities # All entities in model
$sel = $mod.selection # Current selection
$grp_main = $ent.add_group
$view = $mod.active_view

$s = 100.inch
$w = 60.inch
$beta = 0.0085

def build_material()
  n = 10
  (0..n-1).each { |i|
    (0..n-1).each { |j|
      pts = []
      pts[0] = [i*$s,j*$s,0]
      pts[1] = [i*$s,j*$s+$w,0]
      pts[2] = [i*$s+$w,j*$s+$w,0]
      pts[3] = [i*$s+$w,j*$s,0]
      entities2 = $grp_main.entities
      face = entities2.add_face pts
      face.back_material = [200,(255/(n)*j).round,(255/(n)*i).round]
      face.pushpull -40
  }
    }
end  

def scale_object(x)
  height = Math.cos($beta*((x*x + ((x+10)*(x+10))))) #I NEED HELP HERE
  scale_transformation = Geom::Transformation.scaling(1,1,height)
  $grp_main.transformation *= scale_transformation
  $grp_main.transform!(scale_transformation);
end

def repaint(n_times, delay)
  for x in 0..n_times-1
    scale_object(x);
    $view.refresh
    sleep delay;
   end
end
build_material();
repaint(20,0.7);
height = Math.cos($beta*((x*x + ((x+10)*(x+10)))))

在那里,我不知道如何获取x和y坐标...

0 个答案:

没有答案