From 9bebad59c39e150b836f50cdb26c5623c27812f6 Mon Sep 17 00:00:00 2001 From: Ajabep Date: Wed, 14 Jan 2026 21:45:32 +0100 Subject: [PATCH] Fixing trigonometry --- c3cat-bottle-clip/c3cat-bottle-clip.scad | 50 ++++++++++++++++++------ 1 file changed, 38 insertions(+), 12 deletions(-) diff --git a/c3cat-bottle-clip/c3cat-bottle-clip.scad b/c3cat-bottle-clip/c3cat-bottle-clip.scad index ccc1400..a868512 100644 --- a/c3cat-bottle-clip/c3cat-bottle-clip.scad +++ b/c3cat-bottle-clip/c3cat-bottle-clip.scad @@ -480,24 +480,50 @@ module ear(depth, thickness, side_len=30, bend_factor=0.5, stretch_factor=1.2, c depth = depth == undef ? 20 : depth ; thickness = thickness == undef ? 3 : thickness ; - echo("Generating ONE single ear", - depth = depth, - thickness = thickness, - side_len = side_len, - bend_factor = bend_factor, - stretch_factor = stretch_factor, - chamfer = chamfer, - chamfer_shape = chamfer_shape, - details = details - ); - + // $A and $B are the end of the ear + // $C is the higher end point. $A=[0, side_len/2]; $B=[0,-side_len/2]; - $C=[-(side_len/2/sin(120))*1.5*stretch_factor, 0]; + // From the front, an ear looks like: + // + // $C + // /|\ + // / | \ + // / | \ + // /---+---\ + // $B c $A + // + // c is the origin of the ear. + // $Bc$C and $Ac$C are 90deg angles. + // + // The length [$B $A] is `side_len` + // Thus, [$B c] == [c $A] == side_len/2 + // + // Since SOH, sin(angle) = Opposed / Hypotenuse + // sin(angle) = Opposed / Hypotenuse + // sin(angle) * Hypotenuse = Opposed + // Hypotenuse = Opposed / sin(angle) + // + // Thus, the `(side_len/2/sin(120))` implies that "The opposed side of the 120 angle is `(side_len/2)` length" and is the formula to know the size of the hypotenuse. + // Moreover, a 120deg angle in a right rectangle does not exists: the sum of all the angles of a triangle needs to be 180deg. I think the author tried, instead, to use the 60 as an angle, since the sinus is the same. + // + // The correct formula should be `((side_len/2)*tan(60))`: since $C$B$A should a 60deg angle to have an equilateral `$A$B$C` triangle, the product of the tangent ("TOA") of this angle and the adjacent segment [$B c] will give us the size of length of the opposed segment [$C c]. + // + // MOREOVER, the product of the magic number `1.5` with the divisor `sin(120)`... is actually the result of the `tan(60)`! + // + // The original formula was: + // $C=[-(side_len/2/sin(120))*1.5*stretch_factor, 0]; + $C=[-((side_len/2)*tan(60))*stretch_factor, 0]; + + // $a, $b and $c are the distance between the different points of the triangle. $c=sqrt(pow($A.x-$B.x, 2)+pow($A.y-$B.y, 2)); $b=sqrt(pow($A.x-$C.x, 2)+pow($A.y-$C.y, 2)); $a=sqrt(pow($C.x-$B.x, 2)+pow($C.y-$B.y, 2)); + + // $hc is the height of $C. $hc=-$C.x; + + // If I correctly understood, $alpha should be the angle of the $B$A$C. This should be 60deg... but is not. idk why. $alpha=asin($hc/$b); $beta=$alpha; $gamma=180-$alpha-$beta;