JSCAD User Group
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    How to use vec2/3 classes

    Scheduled Pinned Locked Moved Design Discussions
    3 Posts 2 Posters 1.4k Views 1 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • gilboonetG Offline
      gilboonet
      last edited by

      Hello, as I restarted using JSCAD, after a long time using only C language, then vanilla JS, I would like to know how to use the vec2/3 classes, what is the needed require, and how to use them. I remember I used such classes with V1 but with V2 I didn't and for exemple I have code where I need to compute a geometry dimensions and center, so I use
      b = measureBoundingBox()
      then the dimensions are b[1] minus b[0]
      and the center is b[1] minus dimensions' half
      For the moment I'm directly using the values from the returned array.

      gilboonetG 1 Reply Last reply Reply Quote 0
      • gilboonetG Offline
        gilboonet @gilboonet
        last edited by gilboonet

        Just to reply to my own question ...

        const jscad = require('@jscad/modeling')
        const { sphere } = jscad.primitives
        const { vec3 } = jscad.maths
        const { translate } = jscad.transforms
         
        const main = () => {
          let A = vec3.fromValues(15,0,5);
          console.log("A:", A);
          
          let B = vec3.create();
          
          vec3.add(B, A, [50,0,0]);
          
          console.log("B:", B);
          
          let C = vec3.create();
          vec3.add(C, A, B);
          vec3.divide(C, C, [2,2,2]);
          
          return [
            translate(A, sphere({radius:2}))
            ,
            translate(B, sphere({radius:2}))
            ,
            translate(C, sphere({radius:1}))
          ];
        }
         
        module.exports = { main } 
        

        Capture d’écran du 2023-03-01 11-33-03.png

        z3devZ 1 Reply Last reply Reply Quote 0
        • z3devZ Offline
          z3dev @gilboonet
          last edited by

          @gilboonet the example looks fine. You can create, rotate, transform all the math objects..

          Now comes the fun part... curves, distances, etc. There are little tidbits of logic throughout the library. You can find some of the basic calculations in the primitives, I.e. arc, circle, sphere, etc.

          And of course, let us know if you have questions.

          1 Reply Last reply Reply Quote 0

          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

          With your input, this post could be even better 💗

          Register Login
          • First post
            Last post
          Powered by NodeBB | Contributors