2017-03-28 20:56:13 +08:00
# rotate_p
2017-04-29 22:26:57 +08:00
Rotates a point `a` degrees around an arbitrary axis. It behaves as the built-in `rotate` module
2017-03-28 20:56:13 +08:00
## Parameters
2017-04-29 22:26:57 +08:00
- `point` : A 3D point `[x, y, z]` or a 2D point `[x, y]` .
- `a` : If it's `[deg_x, deg_y, deg_z]` , the rotation is applied in the order `x` , `y` , `z` . If it's `[deg_x, deg_y]` , the rotation is applied in the order `x` , `y` . If it's`[deg_x]` , the rotation is only applied to the `x` axis. If it's an number, the rotation is only applied to the `z` axis.
2017-03-28 20:56:13 +08:00
## Examples
You can use the code below to create a line.
2017-03-30 14:22:48 +08:00
include < rotate_p.scad > ;
2017-03-28 20:56:13 +08:00
hull() {
sphere(1);
rotate([0, -45, 45])
translate([20, 0, 0])
sphere(1);
}
2017-03-28 20:58:57 +08:00
The following code has the same effect.
2017-03-28 20:56:13 +08:00
2017-03-30 14:22:48 +08:00
include < rotate_p.scad > ;
2017-03-28 20:56:13 +08:00
point = [20, 0, 0];
a = [0, -45, 45];
hull() {
sphere(1);
translate(rotate_p(point, a))
rotate(a)
sphere(1);
}
![rotate_p ](images/lib-rotate_p-1.JPG )
2017-03-31 13:16:00 +08:00
The `rotate_p` function is useful in some situations. For example, you probably want to get all points on the path of a spiral around a sphere.
2017-03-28 20:56:13 +08:00
2017-03-30 14:22:48 +08:00
include < rotate_p.scad > ;
2017-03-28 20:56:13 +08:00
radius = 40;
step_angle = 10;
z_circles = 20;
2017-03-29 15:30:51 +08:00
points = [for(a = [0:step_angle:90 * z_circles])
2017-03-28 20:56:13 +08:00
rotate_p(
[radius, 0, 0],
[0, -90 + 2 * a / z_circles, a]
)
];
2017-03-29 15:30:51 +08:00
// Once you get all points on the path, you can place anything at each point.
// I just place a sphere as a simple demonstration.
for(p = points) {
translate(p)
2017-03-28 20:56:13 +08:00
sphere(1);
}
2017-03-29 15:30:51 +08:00
%sphere(radius);
2017-03-28 20:56:13 +08:00
![rotate_p ](images/lib-rotate_p-2.JPG )