On Tue, Oct 2, 2012 at 4:58 PM, Francesco Potortì <poto...@isti.cnr.it> wrote: > Please let me know if I should resend this mail elsewhere for archiving > and publishing, or please do it yourself. > > I recently used the Octave geometry package. Nice software. Various > things follow. > > 1) misbehaviour or bug with workaround > There is a problem with the area of polygons, which is computed as > negative if the vertices are counterclockwise. Before using the > polygonCentroid function below I had to check for this. This is how I > did, which may be useful to others or maybe trigger ideas for a better > method: > > a = clipPolygon(c) > if (isCounterClockwise(a(1,:),a(2,:),a(3,:)) < 1) > a = reversePolygon(a); > endif > scopecentr = polygonCentroid(a); > > > 2) contributed software > I wrote three small functions that I think could be added to the > package. I can write docs and tests for them, if required. They are > appended. > > > ## Convert a box [minX maxX minY maxY] to a polygon [X Y] > function poly = box2polygon (box) > p([1 4]) = box(1); > p([2 3]) = box(2); > p([5 6]) = box(3); > p([7 8]) = box(4); > poly = reshape(p,4,2); > endfunction > > ## Clip a polygon with a box > ## Needs pkg 'geometry'. > function poly = clipPolygon (poly, box) > [x y] = oc_polybool(poly,box2polygon(box)); > poly = [x y]; > endfunction > > ## Centroid of a polygon > function centr = polygonCentroid (pl) > centr = shapecentroid(polygon2shape(pl)); > endfunction > > -- > Francesco Potortì (ricercatore) Voice: +39.050.315.3058 (op.2111) > ISTI - Area della ricerca CNR Mobile: +39.348.8283.107 > via G. Moruzzi 1, I-56124 Pisa Fax: +39.050.315.2040 > (entrance 20, 1st floor, room C71) Web: http://fly.isti.cnr.it
Francesco, Thank you very much for your input. 1. didn't you get a warning when using reversed polygons? A reversed polygon will mean a holw in the future, so functions should handle correctly, but definitely not ignore the fact. I will see what I can do. 2. Thank you very much for your functions. I will take a look. If you do not want to leave this forgoten, add the request, together with properly formatted files to the Feature request forum https://sourceforge.net/p/octave/feature-requests/ Remember to follow this minimal instructions (more in the future) http://wiki.octave.org/Contributing_to_the_development_of_packages/modules#Contributing_new_file_or_bundle_of_files Cheers -- M. Sc. Juan Pablo Carbajal ----- PhD Student University of Zürich http://ailab.ifi.uzh.ch/carbajal/ ------------------------------------------------------------------------------ Don't let slow site performance ruin your business. Deploy New Relic APM Deploy New Relic app performance management and know exactly what is happening inside your Ruby, Python, PHP, Java, and .NET app Try New Relic at no cost today and get our sweet Data Nerd shirt too! http://p.sf.net/sfu/newrelic-dev2dev _______________________________________________ Octave-dev mailing list Octave-dev@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/octave-dev