How to tell if a plane is horizontal
-
I know I'll say "duh" when someone tells me the answer, but I need to know if a plane (section_plane, actually) is horizontal.
-
I don't know ruby, but mathematically, you can control if the normal of that face is parallel to the vector (0 0 1)... does this help?
-
.
duh
(is this a ruby question or an ill_located thead?)
-
If you already have required a plane called "myplane", you can get the plane normal and compare it's vector against Z-axis within some tolerance..
I'm not sure if it suffice to simply compare 2 vectors for equality (?) due to floating Point comparison.
BUT in this case Sketchup is creating the vector so perhaps the tolerance is set and you can compare plane_normal against Z_AXIS. Im not certain about that though..
Depending at what the direction the normal is Pointing it might be a good idea to do a tolerance for absolute values. IE discard -1 to 1 for example. Ruby abs could be used.
Even if the sectioncut is horisontal it might be flipped upside down. If you want to trap for that..
So the vector direction might NOT be the same as Z-axis even if parallel.
I'm presuming you already familiar with the API methods for comparing vectors..This could be used as an alternative to abs.
def positivVal(a) a = a < 0 ? -a ; a end
Anyway.
This should get you the plane normal. I got this code from somewhere in this forum, so there IS a thread covering this subject, somewhere..a, b, c, d = myplane plane_normal = Geom;;Vector3d.new(a,b,c)
-
The Geom::Vector3d#== already accounts for floating point tolerance. So, you should create a z-oriented Vector3d and compare it to the normal of the plane using ==. You should not test it to see if x and y are zero and z is 1.0, as that will not account for tolerance.
-
@unknownuser said:
Geom::Vector3d#== already accounts for floating point tolerance
Right. Good to know for sure.
@unknownuser said:
you should create a z-oriented Vector3d and compare it to the normal of the plane using ==
Can't one compare against Z_AXIS ?
Come to think of it. If using a sectioncut all geometry will be on same plane. And "probably" contains faces which could be used to extract a face normal. So a plane might not even get into use. Just compare face normal against Z_AXIS ?
Or if Z_AXIS is not valid comparison object, create a z axis vector like Slbaumgartner said.Jeff
-
@jolran said:
Can't one compare against Z_AXIS ?
Yes, Z_AXIS is just a pre-defined Vector3d oriented z-wards.
@jolran said:
Come to think of it. If using a sectioncut all geometry will be on same plane. And "probably" contains faces which could be used to extract a face normal. So a plane might not even get into use. Just compare face normal against Z_AXIS ?
Jeff
A SectionPlane has an associated Plane, and that is all about the plane that is accessible from Ruby. It is returned by SectionPlane#get_plane as a 4-element Array. The first three elements are the components of the normal vector to the plane, and the fourth is the offset of the plane from the origin along the normal. So, you could form a Vector3D from the SectionPlane's normal and compare with that.
However, you should realize that a SectionPlane is a display animal only - the edges you see displayed are not DrawingEntities and do not exist in any Entities collection of the model. You will not find any Faces to use for determining normal vectors! There are plugins that will generate the DrawingEntities of the cut, but this is not done by a SectionPlane.
Steve
-
Ah, yeah! Youre right off course. I was thinking of a sectioncut, when it's a sectionplane were dealing with, Doh! Should read the topics better hereafter..
Thanks for the lesson. I Think the TO should manage now.
-
nvm
-
Vector normal to the plane seems to simply be the first 3 elements of the 4 that denote a plane. Thanks everyone. CB.
-
@jeff hammond said:
.
(is this a ruby question or an ill_located thead?)
Am I not in the developers forum?
-
@daiku said:
@jeff hammond said:
.
(is this a ruby question or an ill_located thead?)
Am I not in the developers forum?
yes, you are.
every thread isn't always started in the right forum though and your question could be answered in a sketchup way or a ruby way.. the first answer to your question was how to figure it out in sketchup.hence my question.
[+, many members (myself included) browse the forums via the 'new posts' or 'active topics' lists so sub-forums aren't always so obvious since we're basically seeing all forums in one view.. some confusion is bound to happen here&there.. it's ok]
Advertisement