五边形顶点坐标_计算正多边形的顶点坐标

在编程中需要绘制动态平移的任意边数的正多边形,问题是如何根据边数计算正多边形的顶点坐标。解决方案涉及角度和圆的数学知识,每个顶点间的夹角为2π/n,距离原点的距离为r。当原点不为(0,0)时,可以将坐标加上圆心的坐标(x, y)。" 121912227,8450650,Kettle处理Excel:行数据判断与批量导入问题,"['后端开发', '数据处理工具', 'ETL']

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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));

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值