获取Java中Path2D对象的坐标对?

时间:2017-12-09 12:17:36

标签: java java-2d path-iterator

我必须获取Path2D对象中每组坐标的坐标,但我不知道如何。以前我们使用多边形,所以我能够初始化两个长度为Polygon.npoints的数组,然后将它们设置为Polygon.xpointsPolygon.ypoints数组。现在我们正在使用Path2D对象,我不知道如何做到这一点,因为我似乎只能初始化一个PathIterator,它将一个数组作为输入并返回段?有人可以解释如何获取Path2D对象的所有坐标对吗?

1 个答案:

答案 0 :(得分:2)

下面是一个如何获取a的所有段和坐标对的示例 PathIterator

您反复调用Traceback (most recent call last): File "C:\Users\sompatha\Anaconda2\envs\Ml\lib\site-packages\IPython\core\interactiveshell.py", line 2862, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "<ipython-input-1-eeff7c4f34af>", line 1, in <module> import numpy as np File "C:\Users\sompatha\Anaconda2\envs\Ml\lib\site-packages\numpy\__init__.py", line 126, in <module> from numpy.__config__ import show as show_config File "C:\Users\sompatha\Anaconda2\envs\Ml\lib\site-packages\numpy\__config__.py", line 5 blas_mkl_info={'library_dirs': ['C:\Users\sompatha\Anaconda2\envs\ML\\Library\\lib'], 'define_macros': [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)], 'libraries': ['mkl_core_dll', 'mkl_intel_lp64_dll', 'mkl_intel_thread_dll'], 'include_dirs': ['C:\Users\sompatha\Anaconda2\envs\ML\\Library\\include']} ^ SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape 的{​​{3}}方法。 在每次调用时,您都会获得一个段的坐标。 请特别注意,坐标数取决于段类型 (从PathIterator方法获得的返回值)。

currentSegment

您可以使用此方法转储任何currentSegment (因此也适用于public static void dump(Shape shape) { float[] coords = new float[6]; PathIterator pathIterator = shape.getPathIterator(new AffineTransform()); while (!pathIterator.isDone()) { switch (pathIterator.currentSegment(coords)) { case PathIterator.SEG_MOVETO: System.out.printf("move to x1=%f, y1=%f\n", coords[0], coords[1]); break; case PathIterator.SEG_LINETO: System.out.printf("line to x1=%f, y1=%f\n", coords[0], coords[1]); break; case PathIterator.SEG_QUADTO: System.out.printf("quad to x1=%f, y1=%f, x2=%f, y2=%f\n", coords[0], coords[1], coords[2], coords[3]); break; case PathIterator.SEG_CUBICTO: System.out.printf("cubic to x1=%f, y1=%f, x2=%f, y2=%f, x3=%f, y3=%f\n", coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]); break; case PathIterator.SEG_CLOSE: System.out.printf("close\n"); break; } pathIterator.next(); } } RectanglePolygonEllipse2D,...)

等实施
Path2D