1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-16 19:54:29 +02:00

angle_between adds a ccw param

This commit is contained in:
Justin Lin
2021-08-26 21:09:32 +08:00
parent 2355820034
commit b6d86ab4ba
3 changed files with 20 additions and 1 deletions

View File

@@ -0,0 +1,12 @@
function angle_between_ccw_2d(v1, v2) =
let(a = atan2(v1[0] * v2[1] - v1[1] * v2[0], v1 * v2))
a >= 0 ? a : a + 360;
function angle_between_ccw_3d(v1, v2) =
let(
dot = v1 * v2,
lenSq1 = v1[0] ^ 2 + v1[1] ^ 2 + v1[2] ^ 2,
lenSq2 = v2[0] ^ 2 + v2[1] ^ 2 + v2[2] ^ 2,
a = acos(dot / sqrt(lenSq1 * lenSq2))
)
a >= 0 ? a : a + 360;

View File

@@ -8,4 +8,9 @@
*
**/
function angle_between(vt1, vt2) = acos((vt1 * vt2) / (norm(vt1) * norm(vt2)));
use <_impl/_angle_between_impl.scad>;
function angle_between(vt1, vt2, ccw = false) =
!ccw ? acos((vt1 * vt2) / (norm(vt1) * norm(vt2))) :
len(vt1) == 2 ? angle_between_ccw_2d(vt1, vt2) :
angle_between_ccw_3d(vt1, vt2);

View File

@@ -3,4 +3,6 @@ to_do:
- deprecate paths2sections(paths) -> rails2sections(rails)
- deprecate path_scaling_sections(shape_pts, edge_path) -> rail_extruded_sections(shape_pts, rail)
- angle_between adds a ccw param.
- doc: sf add convexity