Grasshopper

algorithmic modeling for Rhino

Does PolygonArea require the polygon to lie on a plane parallel to WorldXY? As far as I can tell, any other orientation causes an inaccurate result, and a plane lined up directly with Z causes it to cease working at all.

The python script here is calculating an area by dividing into triangles from the center of the polygon and summing their individual areas. Rhino's AreaMoments command agrees with its result. The goal's target area and final calculated areas are identical if I set the plane to WorldXY.

I've looked over the PolygonArea.cs source and I admit I find the use of a Vector3d.CrossProduct's .Z for an areadoubled to be some kind of voodoo. If I modify the algorithm to use the .X or .Y I can change which plane works and which fails, but my current use case involves computing multiple polygons with arbitrary orientations.

Any advice?

Views: 1091

Replies to This Discussion

The out-of-plane component of the cross-product is equal to the area of the parallelogram created from the two vectors (i.e. twice the area of the triangle). If the code is using .Z as being double the area of the triangle, then it must be assuming that the two vectors are in the global XY plane. (Or did I misunderstand your question?)

https://mathinsight.org/cross_product

Thanks, I think I have a better grasp of the math involved now. I wrote a modified version of the goal in python which uses Plane.FitPlaneToPoints and maps the points over before computing in order to get accurate results for any polygon orientation. A non-planar polygon will still be an approximation, of course, but combined with a CoPlanar goal this always seems to produce correct areas.

I'm not sure how much of a performance hit it incurs, but it would need to be ported back to c# to make a good comparison to the stock code to find out.

My above script was doing some silly things to try to keep the plane from flipping between iterations, and was causing some cases to fail. I think this works better: assure the measured area is positive (we can't really have negative polygon areas, anyway), and if a *=-1 is necessary compute an inverted ZAxis as well when applying pressures. Also input now requires a polyline rather than a list of points.

planefit PolygonArea v2

If you're interested in learning how to solve equations, there are many ways to learn math riddles. There are a number of different options, but these three programs have some key features in common. The first is a structured approach. Students can learn the fundamental concepts of each grade level with these courses, which were carefully chosen by a team of experienced teachers. Whether you're looking for a U.S. or Canadian version, these programs should be able to help.

what a great polygon, you really did it perfect

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service