Menu

polygon2d

Help
2012-03-25
2012-12-12
  • MikeBriggs2k

    MikeBriggs2k - 2012-03-25

    I'm hoping to use your library in a small project involving a solid polygon shaped region that scales to a max area. The geometry of it all is way over my head. From what I've read in your API, this should be possible with this lib, am I correct? I would then need to use this region to check if a point is inside or out.

     
  • David

    David - 2012-03-26

    Hi Mike,
    I'm not sure I understand your problem: you start from a polygon, then do you want to scale it such as its area reaches a given value (i.e. a given measure), or do want to make the input polygon large enough to fill a given rectangular region (or box) ?
    In the first case, you simply need to (1) measure the area of the input polygon, (2) compute the scaling ratio, (3) create a scaling transform, and (4) apply the transform to the polygon.
    Try something like:
    Polygon poly = …
    double area = Math.abs(poly.getArea());
    double ratio = targetArea / area;
    AffineTransform2D scaling = AffineTransform2D.createScaling(ratio, ratio);
    Polygon2D poly2 = poly.transform(poly);
    double area2 = poly.getArea(); // Should  be equal to the target area

    regards,
    David

     
  • MikeBriggs2k

    MikeBriggs2k - 2012-03-26

    David,

    Thanks, that's pretty much exactly what I was thinking, just wasn't sure where to get the ratios. I was also hoping to use getBuffer to accomplish something similiar to this, http://imgur.com/yWxd8 Is that something your library can do? basically the buffer would just expand until it's area is roughly equal to the given area. All in all, I think your library is amazing, I looked at JTS, but it's far too complex for what I need.  Your library is short sweet and to the point, yet very robust. Two thumbs up.

     
  • David

    David - 2012-03-27

    Hi,

    yes, the buffer is what you expect ! However, I the buffer computation is still not very robust for some cases, so handle with care… And there is no method for computing area of a buffer shape. This should be possible, but I need to take time to implement it.
    And thanks for your feedback, this is always welcome!

    regards,
    David

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.