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

问题描述

我正在寻找一种绘制规则多边形的算法,例如三角形,四边形,五边形,六边形等.

I am looking for an algorithm to draw regular polygon like triangle, quadrangle, pentagon, hexagon etc.

我想这基本上是在解决所有多边形点都位于圆线上的事实.

I guess it`s basically dealing with the fact that all polygon points are located on the line of the circle.

计算多边形对象的那N个点的算法是什么?绘制规则多边形后,我需要根据第一个多边形绘制另一个规则多边形,但旋转K度.

What`s the algorithm to calculate those N points for Polygon object?After drawing a regular polygon I need to draw another regular polygon based on the first one but rotated by K degrees.

推荐答案

使用sin和cos:

double theta = 2 * Math.PI / sides;
for (int i = 0; i < sides; ++i) {
    double x = Math.cos(theta * i);
    double y = Math.sin(theta * i);
    // etc...
}

要旋转,只需向角度添加一个恒定偏移量,即theta * i + offset.

To rotate just add a constant offset to the angle, i.e. theta * i + offset.

这篇关于JAVA绘制规则多边形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 07:29