Code Monkey home page Code Monkey logo

Comments (4)

omgitsraven avatar omgitsraven commented on June 21, 2024 1

You can use %, the modulo operator!
Though note that it can produce some pretty glitchy SDFs, due to the completely abrupt discontinuities; you really might prefer using a twirl after all. (I get use out of %, but only in contexts where there's either plenty of empty space bordering the edges, or the edges always happen to line up smoothly; if you're trying to create an abrupt edge, modulo can't actually do that right, because it can't actually describe the 'open' faces that those edges leave behind!)

from libfive.

lf94 avatar lf94 commented on June 21, 2024

This is kind of what I figured (for why something like frac is not included). I'll give twirl a whirl!

from libfive.

lf94 avatar lf94 commented on June 21, 2024

At first I was like, how with modulus? Then I realized .mod(1). It works damn perfect! I've got bolts again!

1678049418

For anyone that needs it:

const mag = (x, y) => sqrt(x.square().add(y.square()));
const thread = (radius_, screw_) => {
  const [x,y,z] = [X(),Y(),Z()];
  const radius = Value(radius_);
  const screw = Value(screw_);
  const rad = mag(x,y).sub(radius);
  const th = (
    rad.sub(
      abs(
       z.mul(screw).sub(atan2(y)(x)).div(Math.PI / 2)
         .mod(1)
         .sub(0.5)
      ).div(screw)
    )
  );
  return th;
};

const bolt = (diameter, height, pitch) =>
  thread(diameter / 2, pitch)
  .intersection(cylinder(diameter + pitch, height));

from libfive.

lf94 avatar lf94 commented on June 21, 2024

P.S. The twirl series of functions, while do twirl, do not twirl uniformly across the surface. Just a warning to anyone who uses them. They won't look like the twirling shown in my screenshot using my SDF.

from libfive.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.