JustinSDK / dotSCAD

Reduce the burden of mathematics when playing OpenSCAD
https://openhome.cc/zh-tw/openscad/
GNU Lesser General Public License v3.0
784 stars 107 forks source link

along_with has an element out of place #28

Closed clsn closed 2 years ago

clsn commented 2 years ago

I'm doing along_with on a circular path (obtained from shape_circle) and it looks like some of the elements are out of place. It looks like some sort of off-by-one error, but I don't quite see it yet. Two views, one oblique and one from directly above: Screenshot from 2022-04-13 18-13-51 Screenshot from 2022-04-13 18-14-29

Note the two adjacent slabs that are exactly parallel and aligned with each other on the right. Surely that shouldn't happen with a symmetrical path.

Also, all the other slabs aren't facing toward the center symmetrically, as I would have expected (am I wrong to expect that?)

If I get a chance I'll see if I can write a patch for this, but I thought I'd get the ticket made in the meantime.

JustinSDK commented 2 years ago

If you want to place objects precisely, their points and angles are required. For example:

$fn = 16;
a_step = 360 / $fn;

for(i = [0:$fn - 1]) {
    rotate(i * a_step)
    translate([15, 0])
        cube([1, 4, 9], center = true);
}

image

When you have only points or you don't care their precise angles, just as the doc says, along_with currently provides two methods for guessing how to rotate children.

If you want, you may add more methods for guessing how to rotate children. But remember! It's still just a guess. Because you don't provide precise angles, the guessed angles might not what you want.

clsn commented 2 years ago

OK, fair. That's what I wound up doing anyway (not using along_with and writing my own placement routine) since it was just a circle anyway. I guess the lesson here is that I expected more of along_with's guessing powers than I should have. It seems to me that there's an obvious "correct" choice of angles when the curve is a simple circle, but it probably doesn't generalize well into all the paths along_with has to handle.

If I think of a guessing heuristic I think works better I'll write it up.

BrettRD commented 2 years ago

@clsn you might like to try adding a path-is-closed argument to along_with so you can calculate the tangents at the ends as though they were in the middle

JustinSDK commented 2 years ago

@clsn If you have a simple circle, I think it's better to assign the angles parameter directly.

use <along_with.scad>;
use <shape_circle.scad>;

$fn = 16;
step = 360 / $fn;

along_with(shape_circle(15), angles = [each [0:step:360 - step]])
    cube([1, 4, 9], center = true);