Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shear angles do not calculate correctly #49

Open
pkensler opened this issue Nov 24, 2022 · 4 comments
Open

Shear angles do not calculate correctly #49

pkensler opened this issue Nov 24, 2022 · 4 comments

Comments

@pkensler
Copy link

Two compartments in the attached file have the Shear parameter configured. One compartment (Cards) is configured in .scad at 45 but measures closer to 35° in the model. Another compartment (Privilege Tokens) is configured at 80 in .scad but measures 45° in the model.

Shear-Example.scad.txt

@Bumblez
Copy link

Bumblez commented Mar 21, 2023

Any updates on this? I'm running into the same issue... the angles in the shear are off.
I have attached my own example with just 1 compartment at an angle that is supposed to be 55°, but in reality is much less.
(tested with BIT lib version 2.45)

Trial1.scad.txt

[Edit] I had a quick look at the implementation of the Shear() module in the BIT lib file... shouldn't the line for the x angle, which is currently
[ 1, 0, sin(x), 0],
be
[ 1, 0, sin(x)/sin(90-x), 0],

?

@jmickelin
Copy link

jmickelin commented Apr 29, 2023

Yup, should be tan(x).

Moreover, there is another issue with shears (at least for compartments) stemming from the fact that the transformation is applied not on the cube corresponding to the compartment, but to a cube extending through the whole box that is then filled in again in later steps. In essence, this causes the z-translation that is meant to center the component before shearing to move the wrong amount. After undoing the translation, the component origin no longer line up with the center of the slanted face of the cube (which is what is intended according to documentation), but is off by an amount that is hard to account for unless you delve into the code.

To fix this, I ended up writing this correction term:

function shear_correction_y(angle, box_height, compartment_height) = -sin(angle)*(box_height/2 - g_wall_thickness - cos(angle)*compartment_height/2);

or (once the transformation matrix is fixed as pointed out by @Bumblez:

function shear_correction_y(angle, box_height, compartment_height) = -tan(angle)*(box_height/2 - g_wall_thickness - cos(angle)*compartment_height/2);

You then add this term to your position:

...
[BOX_SIZE_XYZ,   [100, 200, 300]],
[ BOX_COMPONENT,
    [
        [CMP_COMPARTMENT_SIZE_XYZ, [30, 60, 90]],
        [CMP_SHEAR, [0, 20]],
        [POSITION_XY,   [10, 10 + shear_correction_y(20, 300, 90)]]
    ]
]
...

This will reliably place the compartment at (10, 10) (with the compartment origin being as described above).

The same thing should work for shearing in the x-direction, but I haven't tested it.

@dppdppd
Copy link
Owner

dppdppd commented Apr 29, 2023 via email

@jmickelin
Copy link

Thanks! I can do the sin(x) -> tan(x) change in a few days and make a PR. I wanna sit down with pen and paper to confirm it's correct, though.

The other problem relating to the positioning might be harder, since I haven't wrapped my head around how the internals work quite yet. (I don't know if you saw my big edit to my post since you're replying via email :) ) But I can take a stab at it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants