sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Question about the vector direction

    Scheduled Pinned Locked Moved Developers' Forum
    4 Posts 3 Posters 441 Views 3 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.
    • W Offline
      wing8b
      last edited by

      Hi, I am new to Sketchup and Ruby, and I am now using SketchUp 7.

      I wonder why the following 2 scripts would have the same result. I suppose them should be in opposite direction...

      Script#1:
      ` centerpoint = Geom::Point3d.new

      Create a circle perpendicular to the normal or Z axis

      vector = Geom::Vector3d.new 0,0,1
      vector2 = vector.normalize!
      model = Sketchup.active_model
      entities = model.active_entities
      edges = entities.add_circle centerpoint, vector2, 5
      face = entities.add_face edges
      status = face.pushpull 100, true`

      Script#2:
      ` centerpoint = Geom::Point3d.new

      Create a circle perpendicular to the normal or Z axis

      vector = Geom::Vector3d.new 0,0,-1
      vector2 = vector.normalize!
      model = Sketchup.active_model
      entities = model.active_entities
      edges = entities.add_circle centerpoint, vector2, 5
      face = entities.add_face edges
      status = face.pushpull 100, true`

      Can anyone advise me on that? Thanks!

      1 Reply Last reply Reply Quote 0
      • Chris FullmerC Offline
        Chris Fullmer
        last edited by

        Yes, it does exactly what you think it should. The vector in script 1 points upwards, while the other points downwards.

        But in SketchUp, any face that is created on z = 0 (the groundplane) that face is always facing downwards. So that effectively overwrites the vector you used in making the circle. In both scripts, try changing the first line to

        centerpoint = Geom::Point3d.new(10,10,10)

        So that it creates the circle up off the groundplane. Then you will see the results you expect where script 1 the tube goes upwards and script 2 the tube goes downwards.

        Hope that helps,

        Chris

        Lately you've been tan, suspicious for the winter.
        All my Plugins I've written

        1 Reply Last reply Reply Quote 0
        • Chris FullmerC Offline
          Chris Fullmer
          last edited by

          A good practice might be to test the normal of the face after it is created. If it's z direction does not match the vector's z direction (vector points upwards but face points downwards) then you should reverse the face, and then proceed with the rest of the script.

          Lately you've been tan, suspicious for the winter.
          All my Plugins I've written

          1 Reply Last reply Reply Quote 0
          • M Offline
            MartinRinehart
            last edited by

            This bit of code is unusual:

            
            vector = ...
            vector2 = vector.normalize!
            
            

            By convention, Ruby methods that end with a "!" work directly on the calling object's data. So vector.normalize! normalizes vector. You now have the normalized data in vector and a second reference to it in vector2. Not sure that was what you intended.

            I added a comment to the Vector3d class doc to clarify this. (If you learned from the doc you were misled.)

            Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

            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