[从头学数学] 第38节 时、分、秒

剧情提要:
[机器小伟]在[工程师阿伟]的陪同下进入练气期第五层功法的修炼,
这次要修炼的目标是[时、分、秒]。

正剧开始:

星历2016年01月11日 13:38:38, 银河系厄尔斯星球中华帝国江南行省。
[工程师阿伟]正在和[机器小伟]一起进一步研究时间,这次时,分,秒都齐全了。


[从头学数学] 第38节 时、分、秒_第1张图片


13:40:34, 小伟看到了增加了秒针的时钟。


[从头学数学] 第38节 时、分、秒_第2张图片


13:41:23, 阿伟也给小伟把时钟改进了。



[从头学数学] 第38节 时、分、秒_第3张图片




13:44:51, 小伟看到了小朋友们辛苦的一天:

[从头学数学] 第38节 时、分、秒_第4张图片

小伟给出了解答:

(1) document.write(clock.secondToTime(clock.elapsedTime([8,20,0],[9,0,0]))+'<br/>');
2400秒 是 0小时40分钟0秒

(4) 10: 55 - 11:35

下课是10分钟,每节课是40分钟。


[从头学数学] 第38节 时、分、秒_第5张图片

这种题怎么比较?

小伟决定把它们都转化到秒来比较:

<span style="font-size:18px;">function myDraw() {  
    var config = new PlotConfiguration();  
    config.init();  
    config.setPreference();  
 
    //config.axis2D(0, 0, 180);  

	var clock = new Clock();
	
	document.write(clock.timeToSecond([0,9,0])+'<br/>');
	document.write(clock.timeToSecond([4,0,0])+'<br/>');
	document.write(clock.timeToSecond([0,24,0])+'<br/>');
	document.write(clock.timeToSecond([0,1,15])+'<br/>');
	document.write(clock.timeToSecond([0,0,65])+'<br/>');
	document.write(clock.timeToSecond([3,0,0])+'<br/>');
	document.write(clock.timeToSecond([0,200,0])+'<br/>');
	document.write(clock.timeToSecond([0,0,140])+'<br/>');
	document.write(clock.timeToSecond([0,2,0])+'<br/>');
	document.write(clock.timeToSecond([0,1,30])+'<br/>');
	document.write(clock.timeToSecond([0,90,0])+'<br/>');
}  

0小时9分0秒 是 540秒
4小时0分0秒 是 14400秒
0小时24分0秒 是 1440秒
0小时1分15秒 是 75秒
0小时0分65秒 是 65秒
3小时0分0秒 是 10800秒
0小时200分0秒 是 12000秒
0小时0分140秒 是 140秒
0小时2分0秒 是 120秒
0小时1分30秒 是 90秒
0小时90分0秒 是 5400秒</span>


<span style="font-size:18px;">function myDraw() {  
    var config = new PlotConfiguration();  
    config.init();  
    config.setPreference();  
 
    //config.axis2D(0, 0, 180);  

	var clock = new Clock();
	document.write(clock.secondToTime(clock.elapsedTime([7,30,0],[7,45,0]))+'<br/>');	
}

900秒 是 0小时15分钟0秒</span>

对于本节的功法,小伟觉得已经完全掌握了。现在他手中的时钟已经具有了以下的多种功能:

<span style="font-size:18px;">/**
* @usage  钟表类
* @author  mw
* @date    2016年01月07日  星期四  15:09:16 
* @param
* @return
*
*/

function Clock() {
	/**
	* @usage   绘制钟表
	* @author  mw
	* @date    2015年12月19日  星期六  14:04:24 
	* @param
	* @return
	*
	*/
	this.drawClock = function(xOff, yOff, r, hour, minute, second) {
		second = second ? second : 0;
		hour = hour % 12;
		minute = minute % 60;
		second = second % 60;
		
		plot.save()
			.translate(xOff, yOff);
		
		//钟面
		strokeCircle(0, 0, r);
		var x = 0, y = 0;
		fillCircle(x, y, r * 0.05);
		for (var i = 0 ; i < 12; i++) {
			x = 0.88 * r * Math.cos(Math.PI / 6 * i);
			y = 0.88 * r * Math.sin(Math.PI / 6 * i);
			
			if (i % 3 == 0) {
				fillCircle(x, y, r * 0.1);
			}
			else {
				fillCircle(x, y, r * 0.05);
			}	
		}
		
		var thitaS = second / 60 * Math.PI * 2 - Math.PI/2;
		var thitaM = (second / 60 + minute) / 60 * Math.PI * 2 - Math.PI/2;
		var thitaH = (hour + (second / 60 + minute) / 60 ) / 12 * Math.PI * 2-Math.PI/2;
		
		//时钟
		var x1 = 0.5 * r * Math.cos(thitaH), 
			y1 = 0.5 * r * Math.sin(thitaH),
			x2 = 0.15 * r * Math.cos(thitaH-Math.PI/18),
			y2 = 0.15 * r * Math.sin(thitaH-Math.PI/18),
			x3 = 0.15 * r * Math.cos(thitaH+Math.PI/18),
			y3 = 0.15 * r * Math.sin(thitaH+Math.PI/18);
		
		plot.setLineWidth(3)
			.beginPath()
			.moveTo(0, 0)
			.lineTo(x2, y2)
			.lineTo(x1, y1)
			.lineTo(x3, y3)
			.closePath()
			.stroke();
		
		//分钟
			x1 = 0.75 * r * Math.cos(thitaM), 
			y1 = 0.75 * r * Math.sin(thitaM),
			x2 = 0.15 * r * Math.cos(thitaM-Math.PI/18),
			y2 = 0.15 * r * Math.sin(thitaM-Math.PI/18),
			x3 = 0.15 * r * Math.cos(thitaM+Math.PI/18),
			y3 = 0.15 * r * Math.sin(thitaM+Math.PI/18);		

		plot.setLineWidth(3)
			.beginPath()
			.moveTo(0, 0)
			.lineTo(x2, y2)
			.lineTo(x1, y1)
			.lineTo(x3, y3)
			.closePath()
			.stroke();
			
		//秒钟
		x1 = 0.85 * r * Math.cos(thitaS), 
		y1 = 0.85 * r * Math.sin(thitaS);
		plot.setStrokeStyle('red')
			.beginPath()
			.moveTo(0, 0)
			.lineTo(x1, y1)
			.closePath()
			.stroke();
			
			
		plot.restore();

	}
	
	this.clock = function(r, hour, minute, second) {
		return this.drawClock(0, 0, r, hour, minute, second);
	}
	
/**
* @usage   打印时间字符串
* @author  mw
* @date    2016年01月11日  星期一  13:00:23 
* @param
* @return
*
*/
	this.time = function(hour, minute, second) {
		var s = '';
		s += hour.toFixed(0)+ ' : ';
		if (minute < 10) 
			s += '0';
		s += minute.toFixed(0) + ' : ';
		if (second < 10)
			s += '0';
		s += second.toFixed(0);
		
		return s;
	}
	
/**
* @usage   计算经过的时间
* @author  mw
* @date    2016年01月11日  星期一  13:00:23 
* @param
* @return  单位为秒
*
*/
	this.elapsedTime = function(timeArray1, timeArray2) {
		//时间矩阵[h, m, s]
		return (timeArray2[0]-timeArray1[0])*3600 + (timeArray2[1]-timeArray1[1])*60 
			+ (timeArray2[2]-timeArray1[2]);
	}
	
	this.secondToTime = function(second) {
		var hour = Math.floor(second / 3600);
		var minute = Math.floor(second / 60) - hour * 60;
		var secondRemain = second % 60;
		var s = second.toFixed(0) + '秒 是 ' +hour.toFixed(0)+'小时' + minute.toFixed(0)+'分钟'+secondRemain.toFixed(0)+'秒';
		return s;
	}
	
	this.timeToSecond = function(timeArray) {
		var second = this.elapsedTime([0,0,0], timeArray);
		var s = timeArray[0].toFixed(0)+'小时'+timeArray[1].toFixed(0)+'分'+
			timeArray[2].toFixed(0)+'秒 是 '+second.toFixed(0)+'秒';
			
		return s;
	}
		
}</span>

13:56:45, 小伟想知道10万秒是多少小时,也想知道一天有多少秒,于是就解答起来:


<span style="font-size:18px;">function myDraw() {  
    var config = new PlotConfiguration();  
    config.init();  
    config.setPreference();  
 
    //config.axis2D(0, 0, 180);  

	var clock = new Clock();
	
	//10万秒是多长的时间
	document.write(clock.secondToTime(100000) + '<br/>');
	//一天有多少秒
	document.write(clock.timeToSecond([24,0,0])+'<br/>');
	
	
}</span>

现在知道了:

100000秒 是 27小时46分钟40秒
24小时0分0秒 是 86400秒


本节到此结束,欲知后事如何,请看下回分解。

你可能感兴趣的:([从头学数学] 第38节 时、分、秒)