java已知圆点坐标和半径,得到圆上的点

最近用自定义View写了一个小游戏,遇到的一个需求。希望对你有帮助...

/**
/*java已知圆点坐标和半径,得到圆上的点
/*CIRCLE_CENTER_X ,CIRCLE_CENTER_Y  圆心坐标
/*CIRCLE_R  圆半径
**/
List points = new LinkedList<Point>();
private void initPointsCircular() {
        for (int i = 0; i < 360; i += 1) {
            int x = (int) (Configs.CIRCLE_CENTER_X - Configs.CIRCLE_R * Math.sin(Math.PI * (i - 90) / 180));
            int y = (int) (Configs.CIRCLE_CENTER_Y - Configs.CIRCLE_R - 10
                    + Configs.CIRCLE_R * Math.cos(Math.PI * (i - 90) / 180));
            points.add(new Point(x, y));
        }
 }

  • 4
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
要在Java中发布shapefile圆文件,可以使用第三方库来实现。以下是一个使用GeoTools库发布shapefile圆文件的示例代码: ```java import java.io.File; import java.io.IOException; import org.geotools.data.FeatureWriter; import org.geotools.data.shapefile.ShapefileDataStore; import org.geotools.data.shapefile.ShapefileDataStoreFactory; import org.geotools.feature.simple.SimpleFeatureBuilder; import org.geotools.feature.simple.SimpleFeatureTypeBuilder; import org.geotools.geometry.jts.JTSFactoryFinder; import org.opengis.feature.simple.SimpleFeature; import org.opengis.feature.simple.SimpleFeatureType; import org.opengis.geometry.Geometry; import com.vividsolutions.jts.geom.Coordinate; import com.vividsolutions.jts.geom.GeometryFactory; import com.vividsolutions.jts.geom.Point; public class PublishShapefileCircle { public static void main(String[] args) throws IOException { // 创建圆心 GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(); Coordinate center = new Coordinate(116.3975, 39.9085); // 圆心坐标 Point point = geometryFactory.createPoint(center); // 添加圆形要素 SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder(); typeBuilder.setName("Circle"); typeBuilder.setCRS(DefaultGeographicCRS.WGS84); // 设置坐标系 typeBuilder.add("geometry", Point.class); // 添加几何字段 typeBuilder.add("radius", Double.class); // 添加半径字段 SimpleFeatureType featureType = typeBuilder.buildFeatureType(); SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(featureType); featureBuilder.add(point); // 设置圆心 featureBuilder.add(1000.0); // 设置半径 SimpleFeature feature = featureBuilder.buildFeature(null); // 创建shapefile文件并保存圆形要素 ShapefileDataStoreFactory dataStoreFactory = new ShapefileDataStoreFactory(); File file = new File("circle.shp"); Map<String, Serializable> params = new HashMap<String, Serializable>(); params.put("url", file.toURI().toURL()); params.put("create spatial index", Boolean.TRUE); ShapefileDataStore dataStore = (ShapefileDataStore) dataStoreFactory.createNewDataStore(params); dataStore.createSchema(featureType); String typeName = dataStore.getTypeNames()[0]; FeatureWriter<SimpleFeatureType, SimpleFeature> writer = dataStore.getFeatureWriter(typeName, Transaction.AUTO_COMMIT); writer.hasNext(); writer.write(); writer.close(); dataStore.dispose(); } } ``` 在这个示例代码中,我们使用GeoTools库创建一个shapefile文件,并保存一个圆形要素。其中,我们使用了JTS库来创建圆心,使用SimpleFeatureTypeBuilder来定义图层的字段信息,使用SimpleFeatureBuilder来创建具体的要素,最后使用ShapefileDataStore来保存shapefile文件。在保存时,需要指定文件名以及是否创建空间索引。 值得注意的是,该示例代码中使用的坐标系为WGS84。如果需要使用其他坐标系,需要修改设置CRS的代码。另外,如果要添加更多的圆形要素,只需要重复添加要素的步骤即可。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值