Java PathIterator是否以顺时针或逆时针顺序为您提供多边形的点?Java PathIterator顺时针或逆时针?
回答
它按点在多边形中定义的顺序“走”。考虑下面的代码示例我刚刮起:
c:\files\j>java ShapeTest
Walking clockwise
Currently at: 2.0 5.0
Currently at: 4.0 4.0
Currently at: 4.0 1.0
Currently at: 0.0 1.0
Currently at: 0.0 3.0
Walking counter-clockwise
Currently at: 0.0 3.0
Currently at: 0.0 1.0
Currently at: 4.0 1.0
Currently at: 4.0 4.0
Currently at: 2.0 5.0
由
import java.awt.Polygon;
import java.awt.geom.PathIterator;
class ShapeTest {
/**
* Use points to make a pentagon
. 2,5
0,3 . . 4,3
0,1 . . 4,1
*/
public static void main(String...args) {
// from the top clockwise
int[] xClock = new int[] { 2,4,4,0,0 };
int[] yClock = new int[] { 5,4,1,1,3 };
// the reverse order from the clockwise way
int[] xCounter = new int[] { 0,0,4,4,2 };
int[] yCounter = new int[] { 3,1,1,4,5 };
Polygon clock = new Polygon(xClock, yClock, 5);
Polygon counter = new Polygon(xCounter, yCounter, 5);
int index = 0;
System.out.println("Walking clockwise");
PathIterator clockIter = clock.getPathIterator(null);
while(!clockIter.isDone() && index < clock.npoints) {
float[] coords = new float[6];
clockIter.currentSegment(coords);
System.out.println("Currently at: " + coords[0] + " " + coords[1]);
clockIter.next();
index++;
}
index = 0;
System.out.println("Walking counter-clockwise");
PathIterator counterIter = counter.getPathIterator(null);
while(!counterIter.isDone() && index < counter.npoints) {
float[] coords = new float[6];
counterIter.currentSegment(coords);
System.out.println("Currently at: " + coords[0] + " " + coords[1]);
counterIter.next();
index++;
}
}
}
为了记录,我不知道为什么那些'0.0 0.0'部分出现。如果有人知道并且可以编辑并发表评论,我会很感激...这仅仅是一个简单的例子,所以我没有太多投入,但是是的... – corsiKa 2012-07-06 16:59:04
那么,你知道什么?一年半后,有人过来,“等等,这是不正确的......”并修复它!真棒。 – corsiKa 2014-01-31 03:44:34
只是一个额外的说明。我测试过,看起来如果你从一个路径创建一个Area并从中获得PathIterator,那么它总是CCW。 – clankill3r 2015-02-12 10:07:37
- 1. CSS3 - 顺时针旋转比逆时针
- 2. 目标C CATransform3DMakeRotation顺时针/逆时针
- 3. 顺时针/逆时针旋转图像
- 4. 多边形顶点 - 顺时针或逆时针
- 5. 识别顺时针或逆时针旋转
- 6. 查找QDial是否顺时针或逆时针旋转
- 7. Flash CS4:顺时针或逆时针旋转对象
- 8. 查找射线是顺时针逆时针还是非逆时针算法
- 9. 电弧是顺时针还是逆时针?
- 10. 带8弧的圆弧svg顺时针和逆时针旋转
- 11. iphone开发 - UIRotationGestureRecognizer(顺时针和逆时针检测)?
- 12. jQuery:以90度增量顺时针/逆时针旋转图像?
- 13. 如何在android中顺时针和逆时针旋转图像?
- 14. 顺时针和逆时针方向旋转图像
- 15. 检测手势是顺时针还是逆时针
- 16. 顺时针和逆时针直流电机在Matlab中Simulink
- 17. 转换逆时针多边形顺时针一个
- 18. JQuery-顺时针旋转div并逆时针旋转
- 19. 不同的行为填补顺时针和逆时针路径
- 20. 如何顺时针和逆时针旋转圆圈?
- 21. 用CGAffineTransformIdentity逆时针转为顺时针方向
- 22. d3圆弧转换逆时针不顺时针
- 23. 如何在android中执行顺时针和逆时针手势
- 24. 使用javascript在div内顺时针或逆时针旋转图像
- 25. 将三维共面点的列表排序为顺时针或逆时针
- 26. 如何顺时针或逆时针旋转图像,以较短者为准?
- 27. 的UIImageView如何跟踪顺时针或逆时针用户运动
- 28. 以逆时针顺序播放
- 29. 排序的一组在顺时针/逆时针顺序3-d点
- 30. 使用WPF故事板顺利顺时针转为逆时针模式
产生按照'PathIterator' API, '迭代器移动到沿着路径转发的下一段只要在那个方向上有更多的点,主要的遍历方向。' – 2012-07-06 16:37:17