rotate_p


計算點繞任意軸轉動後的新座標。轉動的順序為 xyz

參數

  • point : 要被轉動座標 [x, y, z]
  • a : 形式為 [deg_x, deg_y, deg_z],分別代表三個軸要轉的角度。

範例

底下的程式碼可以建立一條線,其中用到了 rotate 模組:

include <rotate_p.scad>;

hull() {
    sphere(1);
    rotate([0, -45, 45]) 
        translate([20, 0, 0]) 
            sphere(1);   
}  

底下的程式碼有相同的結果,不過使用了 rotate_p 函式:

include <rotate_p.scad>;

point = [20, 0, 0];
a = [0, -45, 45];

hull() {
    sphere(1);
    translate(rotate_p(point, a))    
       rotate(a)  
           sphere(1);   
}  

rotate_p

在某些情況下,使用 rotate_p 會是必要的。例如,你可能想取得繞著球的螺線路徑:

include <rotate_p.scad>;

radius = 40;
step_angle = 10;
z_circles = 20;

points = [for(a = [0:step_angle:90 * z_circles]) 
    rotate_p(
        [radius, 0, 0], 
        [0, -90 + 2 * a / z_circles, a]
    )
];

// 一旦你有了路徑上的各個點,就可以在點上放上任何東西了。
// 這邊就簡單放個球。
for(p = points) {
    translate(p) 
        sphere(1);
}

%sphere(radius);

rotate_p