计算正多边形的顶点坐标 [英] Calculate coordinates of a regular polygon's vertices

查看:1731
本文介绍了计算正多边形的顶点坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写一个程序,我需要绘制的两侧任意数量的多边形,每一个被翻译由给定的公式动态变化。还有涉及到一些相当有趣的数学,但我被困在这万阿英,蒋达清。

我如何计算正多边形的顶点具有原点坐标(中,所有角相等),只给双方,最好的(但不是neccessarily)数量在中心?

例如:一个六边形可能有以下几点(均为浮动 S):

 (1.5,0.5 *的Math.sqrt(3))
(0,1 *的Math.sqrt(3))
(-1.5,-0.5 *的Math.sqrt(3))
(-1.5,-0.5 *的Math.sqrt(3))
(0,-1 *的Math.sqrt(3))
(1.5,-0.5 *的Math.sqrt(3))
 

我的方法是这样的:

 无效InitPolygonVertexCoords(RegularPolygon聚)
 

和坐标需要加入到本(或类似的东西,比如一个列表):

 点[] _polygonVertexPoints;
 

我主要的算法有兴趣在这里,但在C#中的例子将是有益的。我甚至不知道从哪里开始。 我应该如何实现呢?它甚至有可能?!

感谢你。

解决方案

 为(i = 0;我n种;我++){
  输出(%F%F \ñ,R * Math.cos(2 * Math.PI * I / N)中,r * Math.sin(2 * Math.PI * I / N));
}
 

其中,研究是circumsribing圆的半径。对不起,我错了语言没有Habla C#。

基本上任何两个顶点之间的角度为 2圆周率/正的和所有顶点都在距原点距离的研究

编辑:的   如果你想有其他中心somewher不是原来的,比如说在(X,Y)

 为(i = 0;我n种;我++){
  输出(%F%F \ñ中,x + R * Math.cos(2 * Math.PI * I / N)中,y + R * Math.sin(2 * Math.PI * I / N));
}
 

I am writing a program in which I need to draw polygons of an arbitrary number of sides, each one being translated by a given formula which changes dynamically. There is some rather interesting mathematics involved but I am stuck on this probelm.

How can I calculate the coordinates of the vertices of a regular polygon (one in which all angles are equal), given only the number of sides, and ideally (but not neccessarily) having the origin at the centre?

For example: a hexagon might have the following points (all are floats):

( 1.5  ,  0.5 *Math.Sqrt(3) )
( 0    ,  1   *Math.Sqrt(3) )
(-1.5  ,  0.5 *Math.Sqrt(3) )
(-1.5  , -0.5 *Math.Sqrt(3) )
( 0    , -1   *Math.Sqrt(3) )
( 1.5  , -0.5 *Math.Sqrt(3) )

My method looks like this:

void InitPolygonVertexCoords(RegularPolygon poly)

and the coordinates need to be added to this (or something similar, like a list):

Point[] _polygonVertexPoints;

I'm interested mainly in the algorithm here but examples in C# would be useful. I don't even know where to start. How should I implement it? Is it even possible?!

Thank you.

解决方案

for (i = 0; i < n; i++) {
  printf("%f %f\n",r * Math.cos(2 * Math.PI * i / n), r * Math.sin(2 * Math.PI * i / n));
}

where r is the radius of the circumsribing circle. Sorry for the wrong language No Habla C#.

Basically the angle between any two vertices is 2 pi / n and all the vertices are at distance r from the origin.

EDIT: If you want to have the center somewher other than the origin, say at (x,y)

for (i = 0; i < n; i++) {
  printf("%f %f\n",x + r * Math.cos(2 * Math.PI * i / n), y + r * Math.sin(2 * Math.PI * i / n));
}

这篇关于计算正多边形的顶点坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆