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 invector
and 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.)
Advertisement