L4K ︰ Python Turtle《六》

小海龜能否御光而行耶??

光在真空裡與均勻的介質中走直線,直到遭遇不同折射率之界面,或者反射、然而通常多折射,它的軌跡就像『折線』 line chart

Graph_(PSF)

This simple graph shows data over intervals with connected points

 

也許這正是『屈光學』名義之由來也。雖說此『折線圖』看來平淡無奇,那要如何描述光之行徑呢?怎樣選取『座標系』才能定位的耶??光學書本一般將此當成不說自明之理!於是直接展開論述,若干圖例後,難免彷彷彿彿似懂非懂的乎!!

─── 摘自《光的世界︰矩陣光學三‧下

 

藉著『斜率』

Slope

In mathematics, the slope or gradient of a line is a number that describes both the direction and the steepness of the line.[1] Slope is often denoted by the letter m; there is no clear answer to the question why the letter m is used for slope, but it might be from the “m for multiple” in the equation of a straight line “y = mx + c”.[2]

  • The direction of a line is either increasing, decreasing, horizontal or vertical.
    • A line is increasing if it goes up from left to right. The slope is positive, i.e.  m>0.
    • A line is decreasing if it goes down from left to right. The slope is negative, i.e.  m<0.
    • If a line is horizontal the slope is zero. This is a constant function.
    • If a line is vertical the slope is undefined (see below).
  • The steepness, incline, or grade of a line is measured by the absolute value of the slope. A slope with a greater absolute value indicates a steeper line

Slope is calculated by finding the ratio of the “vertical change” to the “horizontal change” between (any) two distinct points on a line. Sometimes the ratio is expressed as a quotient (“rise over run”), giving the same number for every two distinct points on the same line. A line that is decreasing has a negative “rise”. The line may be practical – as set by a road surveyor, or in a diagram that models a road or a roof either as a description or as a plan.

The rise of a road between two points is the difference between the altitude of the road at those two points, say y1 and y2, or in other words, the rise is (y2y1) = Δy. For relatively short distances – where the earth’s curvature may be neglected, the run is the difference in distance from a fixed point measured along a level, horizontal line, or in other words, the run is (x2x1) = Δx. Here the slope of the road between the two points is simply described as the ratio of the altitude change to the horizontal distance between any two points on the line.

In mathematical language, the slope m of the line is

  m=\frac{y_2-y_1}{x_2-x_1}.

The concept of slope applies directly to grades or gradients in geography and civil engineering. Through trigonometry, the grade m of a road is related to its angle of incline θ by the tangent function

  m = \tan (\theta)\!

Thus, a 45° rising line has a slope of +1 and a 45° falling line has a slope of −1.

As a generalization of this practical description, the mathematics of differential calculus defines the slope of a curve at a point as the slope of the tangent line at that point. When the curve given by a series of points in a diagram or in a list of the coordinates of points, the slope may be calculated not at a point but between any two given points. When the curve is given as a continuous function, perhaps as an algebraic formula, then the differential calculus provides rules giving a formula for the slope of the curve at any point in the middle of the curve.

This generalization of the concept of slope allows very complex constructions to be planned and built that go well beyond static structures that are either horizontals or verticals, but can change in time, move in curves, and change depending on the rate of change of other factors. Thereby, the simple idea of slope becomes one of the main basis of the modern world in terms of both technology and the built environment.

tangent_function_animation

At each point, the derivative is the slope of a line that is tangent to the curve at that point. Note: the derivative at the point A is positive where green and dash-dot, negative where red and dashed, and zero where black and solid.

 

計算,輔之以記憶數步,可乘浪過海也!!

pi@raspberrypi:~ $ python3
Python 3.4.2 (default, Oct 19 2014, 13:31:11) 
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import turtle, math
>>> turtle.setup(width=1024, height=768)
>>> turtle.shape('turtle')
>>> turtle.mode('logo')
>>> 
>>> x = [5*n for n in range(49)]
>>> y = [100*math.sin(math.pi/120.0*x[n]) for n in range(49)]
>>> 點距 = [math.sqrt( (y[n+1]-y[n])**2 + (x[n+1]-x[n])**2 ) for n in range(48)]>>> 朝向 = [90 - 180.0/math.pi*math.atan( (y[n+1]-y[n])/(x[n+1]-x[n]) ) for n in range(48)]
>>> 起始角度 = 朝向[0]
>>> 第一步長度 = 點距[0]
>>> 餘步列 = 點距[1:]
>>> 
>>> def 正弦移動():
...     保存原向 = turtle.heading()
...     turtle.right(起始角度)
...     turtle.forward(第一步長度)
...     for n in range(47):
...         if 朝向[n+1] > 朝向[n]:
...             turtle.right(朝向[n+1]-朝向[n])
...         else:
...             turtle.left(朝向[n]-朝向[n+1])
...         turtle.forward(餘步列[n])
...     turtle.seth(保存原向)
... 
>>> 正弦移動()
>>> 
>>> def 正弦波動(n):
...     for 幾次 in range(n):
...         正弦移動()
... 
>>> turtle.reset();正弦波動(2)
>>> 
>>> def 八方震盪():
...     for 方向 in range(8):
...         turtle.right(45)
...         正弦波動(2)
...         turtle.penup()
...         turtle.goto(0,0)
...         turtle.pendown()
... 
>>> turtle.reset();八方震盪()
>>> 

 

【正弦移動】

python-turtle-graphics_%e6%ad%a3%e5%bc%a6%e7%a7%bb%e5%8b%95

 

【正弦波動】

python-turtle-graphics_%e6%ad%a3%e5%bc%a6%e6%b3%a2%e5%8b%95

 

【八方震盪】

python-turtle-graphics_%e5%85%ab%e6%96%b9%e9%9c%87%e7%9b%aa

 

何況區區繪圖的乎☆☆

Plotter

The plotter is a computer printer for printing vector graphics. In the past, plotters were used in applications such as computer-aided design, though they have generally been replaced with wide-format conventional printers. A plotter gives a hard copy of the output. It draws pictures on a paper using a pen. Plotters are used to print designs of ships and machines, plans for buildings and so on.

Overview

Digitally controlled plotters evolved from earlier fully analog XY-writers used as output devices for measurement instruments and analog computers.

Pen plotters print by moving a pen or other instrument across the surface of a piece of paper. This means that plotters are vector graphics devices, rather than raster graphics as with other printers. Pen plotters can draw complex line art, including text, but do so slowly because of the mechanical movement of the pens. They are often incapable of efficiently creating a solid region of color, but can hatch an area by drawing a number of close, regular lines.

Plotters offered the fastest way to efficiently produce very large drawings or color high-resolution vector-based artwork when computer memory was very expensive and processor power was very limited, and other types of printers had limited graphic output capabilities.

Pen plotters have essentially become obsolete, and have been replaced by large-format inkjet printers and LED toner based printers. Such devices may still understand vector languages originally designed for plotter use, because in many uses, they offer a more efficient alternative to raster data.

History

A number of printer control languages were created to operate pen plotters, and transmit commands like “lift pen from paper”, “place pen on paper”, or “draw a line from here to here”. Three common ASCII-based plotter control languages are Hewlett-Packard‘s HP-GL, its successor HP-GL/2 and Houston Instruments DMPL. Here is a simple HP-GL script drawing a line :

SP1;
PA500,500;
PD;
PR0,1000;
PU;
SP;

This program instructs the plotter, in order, to take the first pen (SP1 = Select Pen 1), to go to coordinates X=500, Y=500 on the paper sheet (PA = Plot Absolute), to lower the pen against the paper (PD = Pen Down), to move 1000 units in the Y direction (thus drawing a vertical line – PR = Plot Relative), to lift the pen (PU = Pen Up) and finally to put it back in its stall.