Face width and height in 2d
-
Hi all,
I'm currently working on a project where each face's width and height e.g. x and y in 2d are required as if the face was being looked at staright on (like a plan view). I've used bounding box for this but am finding that it is not accurate enough when a face is at an angle in 2d.
Any help or ideas would be greatly appreciated.
Thanks very much
-
Get the vertices of all 4 corners. Use Point3d#distance from any of the 4 points to the other 3. Throw away the longest distance. The two remaining are length & width (assuming you have a rectangle or square).
Todd
-
Hi,
Thanks very much for that. The problem is with faces of varying shapes. I'm trying to find the overall width and height of every face in the model as if the faces were being looked at in a plan view but have no way of knowing how many sides or vertexes a face will have. I've started on a solution based on unfolding each face, but am not sure how well this will work.
Thanks again,
-
perhaps you should explain what your goal is and what your model is...
-
Perhaps you could make a temporary group and add the face into that. Then transform the face so it's flat normal=0,0,1. Rotate it so the longest side is say y=0. Then find the bounding box max/min etc ?
-
It's possible to use vectors to represent axes. The face.normal should be the Z axis, the X axis should be the intersection of a flat (XY) plane with the face plane, and the Y axis can be determined by the cross product of the X and Z axes.
There's also a quicker way to do this after finding the Z axis (the face.normal):
axes = face.normal.axes
xAxis,yAxis,zAxis = axesHowever you do it, once you have the axis vectors, you can then either:
- test the X and Y axes against the points of the face to determine which are minimal and maximal, or
- use an axes transform to convert the vertex positions of the face to the world XYZ coordinates and then determine the minimal and maximal XY values.
Advertisement