绘制围绕圈子的小线的数学 [英] mathematics for drawing little lines around circle

查看:159
本文介绍了绘制围绕圈子的小线的数学的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在一个圆周(如时钟)画线。我怎么能实现这个使用一个for循环?

I have to draw lines around a circle (like in clock). How can i achieve this using a for loop?

推荐答案

我不知道如何在Java中实际绘制一条线,但是从中心点计算坐标(cx,cy) use

I'm not sure how to do the actual drawing of a line in Java but to calculate co-ordinates from a central point (cx,cy) use

px = cx+sin(a)*r
py = cy+cos(a)*r

其中 a - 我认为是180degress =π弧度)和 r 是半径。

Where a is the angle (in radians - I think ie 180 degress=π radians) and r is the radius.

外部你需要使用这个公式,半径为100,半径为105,并在两组坐标之间绘制。

To draw the little lines around the outside you would need to use this formula with say a radius of 100 and the also with a radius of 105 and draw between the two sets of co-ordinates.

例如

for (var a=0,aMax=(2*Math.PI),aStep=(Math.PI/30); a<aMax; a+=aStep){
    px1 = cx+Math.sin(a)*r;
    py1 = cy+Math.cos(a)*r;
    px2 = cx+Math.sin(a)*(r+5);
    py2 = cy+Math.cos(a)*(r+5);

    //draw line between (px1,py1) and (px2,py2)
};

这篇关于绘制围绕圈子的小线的数学的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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