Polygon area and max width, height

41 views
Skip to first unread message

ddiaz...@gmail.com

unread,
Sep 4, 2014, 5:58:26 AM9/4/14
to jsxg...@googlegroups.com
Hi!

First of all, thank you for such great lib.
Extremely powerful and easy to use.


So far I have been playing with polygon, intersections, etc.
Is there anyway to get the max width and height of a polygon?  Basically it will be the width and height of the area it contains.

And harder thing: hwo to compute the polygon area?


Thanks a lot in advance.

David

Alfred Wassermann

unread,
Sep 8, 2014, 4:53:24 AM9/8/14
to jsxg...@googlegroups.com, ddiaz...@gmail.com

Hi David,
for polygons there already exists the method Area. But it only is correct for convex polygons.
I just implemented a new method boundingBox, which will be be available in tonight’s nightly build.
From this you easily can determine width and height. The documentation of the method will be:

        /** 
         * Returns bounding box of a polygon. The bounding box is an array of four numbers: the first two numbers 
         * determine the upper left corner, the last two number determine the lower right corner of the bounding box. 
         *  
         * The width and height of a polygon can then determined like this: 
         * @example 
         * var box = polygon.boundingBox(); 
         * var width = box[2] - box[0]; 
         * var height = box[1] - box[3]; 
         *  
         * @returns {Array} Array containing four numbers: [minX, maxY, maxX, minY] 
         */

Volunteers to implement an area method for arbitrary polygons are highly welcome…

Best wishes,
Alfred

Alfred Wassermann

unread,
Sep 8, 2014, 5:01:35 AM9/8/14
to jsxg...@googlegroups.com, ddiaz...@gmail.com
Correction: the Area method in JSXGraph is correct for convex AND concave polygons. The only restriction is that the polygon must not be self-intersecting.
Best wishes,
Alfred


dd...@storelabs.com

unread,
Sep 9, 2014, 3:13:59 AM9/9/14
to jsxg...@googlegroups.com, ddiaz...@gmail.com
Hi Alfred,
thanks a lot for your help.
Checked the area stuff and works great.

I will catch the nightly build to play with the max dimensions.

Thank you for all help and adding that functionality  ;)


Best
David
Reply all
Reply to author
Forward
0 new messages