Skip to content
pentacular edited this page Sep 12, 2019 · 3 revisions

Open #globe

const circleFn = (value) => [sin(value * -360), cos(value * -360)];

const squareFn = (value) => {
  const angle = value * 360;
  const phi = ((angle + 45) % 90 - 45);
  const radius = 1 / cos(phi);
  return vec.scale(radius, circleFn(value));
}

const sphereFn = (latitude, longitude) =>
  vec.add([0, 0, cos(latitude * 180)],
          vec.scale(sin(latitude * 180),
                    circleFn(longitude)));

const cylinderFn = (latitude, longitude) =>
  vec.add([0, 0, cos(latitude * 180)],
          circleFn(longitude));

const hornFn = (latitude, longitude) =>
  vec.rotateX(latitude * Math.PI * 1,
              [0, 5, 0],
              vec.multiply([0.5, 0.5, 1],
                           cylinderFn(latitude, longitude)));

const s = Cylinder.fromFunction(hornFn, 16);

const bracket = assemble(
    Sphere(4)
      .rotateX(90)
      .withLabel('S')
      .move(0, 5)
      .as('globe'),
    Cylinder(1, 0.5)
      .rotateX(90)
      .withLabel('B')
      .as('bearing'),
    Cylinder(1, 0.5)
      .rotateX(90)
      .withLabel('A')
      .move(0, 10)
      .as('bearing'),
    s.as('horn'))
  .rotateX(90 - 23.5);

const { A, B, S } = bracket.labels();

log(`S: ${S}`);

const S0 = [S[0], S[1], -1];
const S1 = [S[0], S[1], -2];

const design = assemble(
         bracket,
         Cylinder
               .between({ radius: 0.5 }, A, B)
               .as('axle'),
         assemble(
             Plan.Label('S0', S0),
             Cylinder(1)
               .orient({ from: S0, at: S }),
             Cylinder(4)
               .orient({ from: S1, at: S }))
           .as('base'))
  .scale(5);
  
await design.keep('bearing', 'horn', 'base')
            .writeStl('stand.stl');
            
await design.keep('globe', 'axle')
            .writeStl('globe.stl');
            
return design;
Clone this wiki locally