开发者

mathematics for drawing little lines around circle

I have to draw lines around a circle (like in clock). How can i achieve t开发者_高级运维his using a for loop?

mathematics for drawing little lines around circle


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

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

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.

eg

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


Have a look at the source code of CoolClock.


you should read up on basic trigonometry and focus on Quadrants to achieve that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜