java applet时钟程序时针坐标的算法怎么回事弄不懂了,大侠帮忙

来源:百度知道 编辑:UC知道 时间:2024/06/26 01:01:27
// Paint is the main part of the program
public void update(Graphics g) {
int xh, yh, xm, ym, xs, ys;
int s = 0, m = 10, h = 10;
String today;

currentDate = new Date();

formatter.applyPattern("s");
try {
s = Integer.parseInt(formatter.format(currentDate));
} catch (NumberFormatException n) {
s = 0;
}
formatter.applyPattern("m");
try {
m = Integer.parseInt(formatter.format(currentDate));
} catch (NumberFormatException n) {
m = 10;
}
formatter.applyPattern("h");
try {
h = Integer.parseInt(formatter.format(currentDate));
} catch (NumberFormatException n) {
h = 10;
}

// Set position of the ends of the

他这个没用圆,用了三角函数。十二个小时是360°,一个小时就是30°。那么假设从12:0:0算起,现在若是h:m:s那么应该时针应该转过了(h+m/60+s/360)*30,等于h*30+m/2+s/12,只不过s/12太小了没有算,然后乘于π/180是把他转换成弧度制,再减去π/2转换成它的余角,然后cos*30,30应该是时针的长度吧,余弦值乘于斜边得到时针水平方向的长度,加上中心x坐标,得到时针x坐标,在具体就不好描述了,你学过几何吧,很简单的,画个图自己试试