java 任意形状,Java中两个形状/区域之间的距离?

If I have two java.awt.geom.Area's made out of the union of various simple Shapes (Polygons and Ellipses), is there a method out there to find the distance (i.e. closest distance) between the two Areas?

To clarify: suppose I have two arbitrary Areas, each of which is created from the union of shapes of any sort:

//Define the first area

Area a = new Area(new Ellipse2D.Double(50, 50, 100, 100));

a.add(new Area(new Rectangle2D.Double(100, 100, 100, 100)));

//Define the second area

Area b = new Area(new Ellipse2D.Double(200, 300, 100, 100));

b.add(new Area(new Ellipse2D.Double(250, 250, 100, 100)));

What I want is a method getDistance(Area a, Area b) that gives me a double representing the shortest distance between any point in Area a and any point in Area b. Here's an image of the above two Areas with a line in blue indicating the distance I'm interested in:

3xKgV.png

Is there a method out there to do this? If not, how might I implement one?

解决方案

There doesn't seem to be a method that does that exactly; however, using PathIterators, you should be able to compare point to point along the outline of the shapes and find the distance manually.

This Wikipedia article describes how you could efficiently implement this to avoid the quadratic obvious implementation.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值