多边形座标 [英] polygon coordinates

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

问题描述

我们如何绘制多边形.当只给出边和半径时. 我必须制作一个弹出框,将输入半径和边数作为输入,并绘制一个多边形.只需公式即可.

how can we draw a polygon. when only the sides and radius is given. I have to make a pop up box which will take as input the radius and number of sides and will draw a ploygon. just need the formula.

推荐答案

想象一个半径为r的圆.就像一个具有无限多个边的规则多边形.

Imagine a circle of radius r. It is like a regular polygon with an infinite number of sides.

三角学告诉我们:

x = r * cos(a);
y = r * sin(a);

我们知道一个圆圈有360度或2pi弧度.因此,要绘制它,我们将以angle = 0开始,计算该坐标,然后步入下一个角度并计算该点,然后在两者之间画一条线.

We know there are 360 degrees or 2pi radians in a circle. So to draw it we would start with angle = 0, calculate that co-ord, step to the next angle and calculate that point, then draw a line between the two.

我们只能在圆的边缘上计算出很多点,最终不会有任何区别.如果圆圈足够小,则即使8个侧面也会看起来是圆形的.

There are only so many points we can calculate around the edge of the circle, eventually it won't make any difference. If the circle is small enough, even 8 sides will look round.

要绘制一个8边的圆,我们希望在圆上均匀分布8个点.将圆分成8个角度,每个角度为2 * pi/8弧度.

To draw an 8 sided circle we want 8 points evenly spaced around the circle. Divide the circle into 8 angles, each one is 2 * pi / 8 radians.

所以:

angle = 0.0;
step = 2 * pi / 8;

for ( n = 0; n < 8; n++ ) {
    x = radius * cos(angle);
    y = radius * sin(angle);
    angle += step;
}

现在您可以绘制一个八边形,将其更改以绘制一般情况.

Now you can draw an octagon, change it to draw the general case.

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

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