Question about the vector direction
-
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.newCreate 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.newCreate 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!
-
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
-
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.
-
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!normalizesvector. You now have the normalized data invectorand a second reference to it invector2. 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.)
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 LoginAdvertisement