JSCAD User Group

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups

    How to use vec2/3 classes

    Design Discussions
    2
    3
    414
    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.
    • gilboonet
      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.

      gilboonet 1 Reply Last reply Reply Quote 0
      • z3dev
        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
        • gilboonet
          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

          z3dev 1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Powered by NodeBB | Contributors