OpenSCAD general discussion Mailing-list

### Re: solar cell mount math fail

JB
Jordan Brown
Wed, May 24, 2023 12:02 AM

BTW, if anybody is curious here's the OpenSCAD program that generated
that diagram.  It's got some examples of using trig to position and size
things.

``````n = 3;
t = 2;
r = 100;
a = 360/n;

module label(t) { text(t, halign="center", valign="center"); }

circle(r=r);
color("gray") rotate(180) translate([0,0,1]) circle(r=r, \$fn=n);
color("white") translate([0,0,2]) {
rotate(a/2) translate([0,-t/2]) square([r,t]);
rotate(-a/2) translate([0,-t/2]) square([r,t]);
translate([0,-t/2]) square([r*cos(a/2),t]);
}

A = [0,0];
B = [r*cos(a/2), r*sin(a/2)];
C = [r*cos(a/2), 0];
D = [r*cos(a/2), -r*sin(a/2)];
color("black") translate([0,0,3]) {
translate(A) label("A");
translate(B) label("B");
translate(C) label("C");
translate(D) label("D");
}
``````

Come to think of it, I could have positioned B and D by translating them
out to X=+r and then rotating, rather than by calculating the
coordinates.  (Rotation to restore them to being upright left as an
exercise for the reader.)  I can't immediately think of a non-trig way
to position C.

BTW, if anybody is curious here's the OpenSCAD program that generated that diagram.  It's got some examples of using trig to position and size things. n = 3; t = 2; r = 100; a = 360/n; module label(t) { text(t, halign="center", valign="center"); } circle(r=r); color("gray") rotate(180) translate([0,0,1]) circle(r=r, \$fn=n); color("white") translate([0,0,2]) { rotate(a/2) translate([0,-t/2]) square([r,t]); rotate(-a/2) translate([0,-t/2]) square([r,t]); translate([0,-t/2]) square([r*cos(a/2),t]); } A = [0,0]; B = [r*cos(a/2), r*sin(a/2)]; C = [r*cos(a/2), 0]; D = [r*cos(a/2), -r*sin(a/2)]; color("black") translate([0,0,3]) { translate(A) label("A"); translate(B) label("B"); translate(C) label("C"); translate(D) label("D"); } Come to think of it, I could have positioned B and D by translating them out to X=+r and then rotating, rather than by calculating the coordinates.  (Rotation to restore them to being upright left as an exercise for the reader.)  I can't immediately think of a non-trig way to position C.
K
Ken
Wed, May 24, 2023 11:35 AM

Thanks Jordan, that piece of code's a keeper- besides the circumscribed
circle, it also neatly give the radius of the inscribed circle as well.

On 2023-05-24 10:02, Jordan Brown wrote:

BTW, if anybody is curious here's the OpenSCAD program that generated
that diagram.  It's got some examples of using trig to position and
size things.

`````` n = 3;
t = 2;
r = 100;
a = 360/n;

module label(t) { text(t, halign="center", valign="center"); }

circle(r=r);
color("gray") rotate(180) translate([0,0,1]) circle(r=r, \$fn=n);
color("white") translate([0,0,2]) {
rotate(a/2) translate([0,-t/2]) square([r,t]);
rotate(-a/2) translate([0,-t/2]) square([r,t]);
translate([0,-t/2]) square([r*cos(a/2),t]);
}

A = [0,0];
B = [r*cos(a/2), r*sin(a/2)];
C = [r*cos(a/2), 0];
D = [r*cos(a/2), -r*sin(a/2)];
color("black") translate([0,0,3]) {
translate(A) label("A");
translate(B) label("B");
translate(C) label("C");
translate(D) label("D");
}
``````

Come to think of it, I could have positioned B and D by translating
them out to X=+r and then rotating, rather than by calculating the
coordinates.  (Rotation to restore them to being upright left as an
exercise for the reader.)  I can't immediately think of a non-trig way
to position C.