Right and Left Handedness
-
I'm working on my Foundation Plugin and trying to develop the polygon tool so that at types of shapes can be input by the user. I will use the "Follow Me" tool and the "Union" tool to create the final solid (concrete). The problem I am encountering is trying to determine if the polygon points describe a left hand or right hand polygon (points are in a clockwise or counter-clockwise direction). This will affect how I create the profile that is extruded along the path to create the footing for the foundation.
Has anyone ever encountered this same problem before? There is probably an easy solution but at the moment I am coming up short.
-
If a polygon has a face then
face.normal
determines the direction thatface.pushpull
will extrude it.In general if you specify a separated polygon's vertices in a ccw order, then the face normal is 'up', and in cw order it's 'down' [aka the right-hand rule - whereby you curl your right hand's fingers and extend the thumb - the curl give the ccw/cw-nwss and the thumb's direction is the face's normal] - BUT there is one exception - when the face is flat on the ground -
face.bounds.center.z==0 && face.normal.parallel?(Z_AXIS)
- in that case irrespective of the loop's ccw/cw-ness theface.normal
is always 'down' - just like the way manually drawing a rectangle in SketchUp is affected - the theory being that you are going to want to pushpull the face upwards and leave the resultant 3d extrusion with a bottom that is facing downwards...
It's easy trapped for this 'flat' event and to adjust your pushpull direction accordingly - although I expect your 'profiles' are probably to be used vertically, so the likelihood of a 'flat' event is very unlikely.Incidentally the order of vertices around a punched hole is reversed when compared to those around an outer-loop.
-
As always you are a cornucopia of knowledge, thank-you for expounding on the handedness of polygons, not a light subject. This is why this stuff never gets old, just when I think I've encountered everything I need to know about SketchUp and its API along comes another mathematical, topological, or geometric challenge.
Unfortunately, with the polygon tool for slab and stemwall foundations the polygon or face created by the points/vertices will typically be "flat", normal vector parallel to the Z-axis.
On a different note I really hope Ruby has a good method(s) for handling matrices and all of the basic matrix manipulations. I am looking forward to creating a plugin that duplicates what I created in Perl a couple years ago and do some full on Matrix Analysis of Trusses (2D at first).
http://design.medeek.com/calculator/calculator.pl
This little web app is what accidentally led me to create the truss plugin.
-
If your faces are always going to be 'flat' - i.e. every vertex's Z is the same - and therefore
face.normal.parallel?(Z_AXIS)
- then the direction of the face's outer edge loop becomes academic.
If you want to extrude it upwards, just invokeface.reverse! if face.normal==Z_AXIS
This makes sure it always faces downwards, ignoring any loop ccw/cw-ness and Z value, and then the extrusion made with pushpull needs to be 'negative' [e.g.-@depth
] to pull it upwards - the pushpulled direction is always opposite to the face's normal vector's direction...
Matrices in Ruby:
http://ruby-doc.org/stdlib-2.0.0/libdoc/matrix/rdoc/Matrix.html
your need to include
requite('matrix.rb')
before invoking any of its methods...
An example of its usage:
https://gist.github.com/d7om/2838551
Note that this example also usesrequire('pp.rb')
- 'pretty-print' to format the output...Note that 'matrix' is separate from SketchUp's
Geom::Transformation
, which uses a matrix, and has its own tools to manipulate data... -
The push-pull direction is irrelevant in this instance. I will always push-pull down. However, I still need to know the handedness of the polygon since the orientation of the face that will be extruded along the polygon using the follow me method will depend on this.
The only way I can think of to do this is to check if a specific point is on the face that is constructed by the polygon points.
-
The pushpull direction is still important.
As you will always be going to push the face down, then all you need to do is to make all of your faces look upwards.
Rather than worry about the loop ccw/cw-ness [which will fail at z=0 as a ccw face will swap to look downwards anyway !] - instead just add the flat face [its loop-direct unimportant], thenface.reverse! if face.normal==Z_AXIS.reverse
Again you need to do a -ve pushpull, so that the top face [now always looking upwards' is retained as the form extrudes downwards...
You seem to be making this more convoluted than it needs to be...
Advertisement