/**
* Copyright (c) 2009-2011, chunquedong(YangJiandong)
*
* This file is part of ChunMap project
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE(Version >=3)
*
* History:
* 2010-05-05 Jed Young Creation
*/
package chunmap.model.operate.buffer;
import java.util.ArrayList;
import java.util.List;
import chunmap.model.coord.CoordSeqEditor;
import chunmap.model.coord.Coordinate2D;
import chunmap.model.coord.CPoint;
import chunmap.model.geom.Ring;
import chunmap.model.geom.Polygon;
/**
* @author chunquedong
*
*/
public class PointBuffer {
public Polygon createBuffer(CPoint p, double distance, double pointNum) {
if (distance <= 0 || pointNum <= 3) {
throw new IllegalArgumentException(
"very little pointNum or distance in pointBuffer");
}
List<CPoint> points = new ArrayList<CPoint>();
double af = 6.28 / pointNum;
for (double a = 0; a < 6.28; a += af) {
double dx = Math.sin(a) * distance;
double dy = Math.cos(a) * distance;
CPoint pp = new Coordinate2D(p.getX() + dx, p.getY() + dy);
points.add(pp);
}
CoordSeqEditor ls = new CoordSeqEditor(points);
ls.close();
Polygon pg = new Polygon(new Ring(ls.toCoordinateSeq()));
return pg;
}
public Polygon createBuffer(CPoint p, double d) {
return createBuffer(p, d, 20);
}
}