本文介绍了创建于Java 2D的复合形状的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Java 2D我修补一些贝塞尔曲线(的CubicCurve2D )共同打造的斑点。我现在面临的问题是如何:

Using Java 2D I've patched several Bezier curves (CubicCurve2D) together to create a "blob". The problem I now face is how to:

  1. 在有效地填充与给定的颜色的斑点。
  2. 在有效地确定一个给定的点是否在BLOB中。

我注意到THST 的CubicCurve2D 工具图形它提供了大量的包含方法确定insideness和的Graphics2D 可以通过<$ C $三来一补一图形 >填充(形状)(我相信使用图形的getPathIterator 方法做本)。

I noticed thst CubicCurve2D implements Shape which provides numerous contains methods for determining "insideness" and that Graphics2D is able to fill a Shape via the fill(Shape) (which I believe uses Shape's getPathIterator methods to do this).

鉴于这一点,我希望我能创造一个复合图形,因此我的getPathIterator(的AffineTransform)方法只会链接底层的PathIterator 取值在一起。然而,这是产生 NoSuchElementException异常一旦我的形状包含多个的CubicCurve2D 。即使我不管理,以实现这一目标,我不相信它会正常运行,因为的CubicCurve2D 总是充满凸侧,和我的斑点是由凹凸曲线。 包含问题更是难上加难作为一个​​点可以合法地趴在BLOB内,但不是在任何个人曲线。

Given this I was hoping I could create a composite Shape, whereby my getPathIterator(AffineTransform) method would simply link the underlying PathIterators together. However, this is producing a NoSuchElementException once my shape contains more than one CubicCurve2D. Even if I do manage to achieve this I'm not convinced it will work as expected because a CubicCurve2D is always filled on the convex side, and my "blob" is composed of concave and convex curves. The "contains" problem is even harder as a point can legitimately lie within the blob but not within any of the individual curves.

  • 我在正确的方式处理这个问题(试图实施图形?)还是有一个惯用的方式,我不知道这样做呢?我本来以为合成几何形状的问题,将是相当普遍的。
  • 有没有人有关于如何解决这个问题?
  • 任何建议
  • Am I approaching this problem in the correct way (trying to implement Shape?) or is there an idiomatic way to do this that I'm unaware of? I would have thought that the problem of compositing geometric shapes would be fairly common.
  • Does anyone have any suggestions regarding how to solve this problem?

在此先感谢。

推荐答案

我不知道我理解你的问题,但是的复合形状的可以与类的。

I'm not sure I understand your question but composite shapes can be created with the class java/awt/geom/Area.

这篇关于创建于Java 2D的复合形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 05:54