作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
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++;
}
}
}
关于Java PathIterator顺时针还是逆时针?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11366040/
我已经很长时间没有使用数学了,这应该是一个简单的问题。 假设我有两个点 A:(1, 0) 和 B:(1, -1)。 我想使用一个程序(Python 或任何编程语言)来计算 A、原点 (0, 0) 和
我有一个用点表示的凸多边形。点由x 坐标数组 和y 坐标数组 表示。 例如: X = {6, 1, 5, 0, 3} Y = {4, 0, 0, 4, 6} 如何按顺时针排序这些点?点数并不总是相同,
我正在开发一个项目,使用这段代码将一个元素拖到另一个圆形元素周围:http://jsfiddle.net/sandeeprajoria/x5APH/11/ function rotateAnn
我有一个二维矩阵 M[N][N],我需要将其逆时针旋转 90 度。我已经看到很多顺时针旋转的答案,但我找不到逆时针旋转的答案。这两个操作有多相似? 最佳答案 如果您反转每一行的顺序,然后顺时针旋转以相
对于我不会涉及的上下文,我需要两个本质上互为倒数的函数。 angle_to() 应该返回钟针从 0° 到连接 p1 和 p2 的线所必须转动的度数>(即 p1 是旋转中心),其中 p1 和 p2 都是
我是一名优秀的程序员,十分优秀!