sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    🫛 Lightbeans Update | Metallic and Roughness auto-applied in SketchUp 2025+ Download

    Odd Math

    Scheduled Pinned Locked Moved Developers' Forum
    3 Posts 2 Posters 270 Views 2 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.
    • J Offline
      Jim
      last edited by

      Can anyone explain the results of this snippet?

      
      model = Sketchup.active_model
      entities = model.entities
      selection = model.selection
      camera = model.active_view.camera
      
      cdir = camera.direction
      puts "camera dir; #{ cdir.inspect}"
      sum = cdir.x.abs + cdir.y.abs + cdir.z.abs
      puts "sum; #{sum.inspect}"
      puts "sum == 1? #{sum == 1}"
      
      

      Results:

      
      camera dir; Vector3d(0, 1, 0)
      sum; 1
      sum == 1? false
      
      

      Hi

      1 Reply Last reply Reply Quote 0
      • AdamBA Offline
        AdamB
        last edited by

        Yes. .to_s / .inspect print an approximation of the Float value. When it prints (0,1,0), thats just the answer to 4 significant figures. Your Float(1) comparison simply shows that difference.

        Developer of LightUp Click for website

        1 Reply Last reply Reply Quote 0
        • J Offline
          Jim
          last edited by

          Thanks Adam. I still don't understand why sum (which is a Float)shown as 1 instead of 1.0

          Might the .inspect method be over-ridden?

          Hi

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post
          Buy SketchPlus
          Buy SUbD
          Buy WrapR
          Buy eBook
          Buy Modelur
          Buy Vertex Tools
          Buy SketchCuisine
          Buy FormFonts

          Advertisement