如何旋转我生成的六角形点或生成六角形点,以便第一个点位于中心顶点? [英] How do I rotate hexagon points I've generated or generate it so that the first point is center-top?
本文介绍了如何旋转我生成的六角形点或生成六角形点,以便第一个点位于中心顶点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
var points = 6;
var width = w;
var height = h;
var angle =((2 * Math.PI)/ points);
var hexagon = [];
for(i = 0; i hexagon.push({
x:width * Math.cos(angle * i),
y:height * Math.sin(angle * i)
})
}
这将产生6点/位置,如果我在它们之间绘制一条线,我会得到一个六角形,但我想要旋转点或以不同方式生成点,以便第一个点总是居中,如下所示:
我该如何去做你可以交换 sin
和<$ c $ c> cos 。
So I have this code:
var points = 6;
var width = w;
var height = h;
var angle = ((2 * Math.PI) / points);
var hexagon = [];
for (i = 0; i < points; i++) {
hexagon.push({
x: width * Math.cos(angle * i),
y: height * Math.sin(angle * i)
})
}
Which will produce 6 points/locations and if I draw a line between them I get a hexagon, but I want to rotate the points or generate the points differently so that the first point is always center-top, like so:
How would I go about doing that?
解决方案
You could just swap sin
and cos
.
这篇关于如何旋转我生成的六角形点或生成六角形点,以便第一个点位于中心顶点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文