L4K ︰ Python Turtle《八》

據說小海龜『參圓格物』多時,終於發現『直達』 goto 和『轉向』 turn 的匯通處。由於言之未詳史無所載,此刻強為解說,難免生吞活剝也 。簡言之︰畫圓之理,『曲率』處處均一,故而重複進一步 forward 1 恆向 轉一度 right 1 【※ or left 1 】可以擬 ○ 矣。

Curvature

In mathematics, curvature is any of a number of loosely related concepts in different areas of geometry. Intuitively, curvature is the amount by which a geometric object such as a surface deviates from being a flat plane, or a curve from being straight as in the case of a line, but this is defined in different ways depending on the context. There is a key distinction between extrinsic curvature, which is defined for objects embedded in another space (usually a Euclidean space) – in a way that relates to the radius of curvature of circles that touch the object – and intrinsic curvature, which is defined in terms of the lengths of curves within a Riemannian manifold.

This article deals primarily with extrinsic curvature. Its canonical example is that of a circle, which has a curvature equal to the reciprocal of its radius everywhere. Smaller circles bend more sharply, and hence have higher curvature. The curvature of a smooth curve is defined as the curvature of its osculating circle at each point.

Curvature is normally a scalar quantity, but one may also define a curvature vector that takes into account the direction of the bend in addition to its magnitude. The curvature of more complex objects (such as surfaces or even curved n-dimensional spaces) is described by more complex objects from linear algebra, such as the general Riemann curvature tensor.

This article sketches the mathematical framework which describes the curvature of a curve embedded in a plane and the curvature of a surface in Euclidean space.

Precise definition

Suppose that C is a twice continuously differentiable immersed plane curve, which here means that there exists a parametric representation of C by a pair of functions γ(t) = (x(t), y(t)) such that the first and second derivatives of x and y both exist and are continuous, and

 

throughout the domain. For such a plane curve, there exists a reparametrization with respect to arc length s. This is a parametrization of C such that

  [5]

The velocity vector T(s) is the unit tangent vector. The unit normal vector N(s), the curvature κ(s), the oriented or signed curvature k(s), and the radius of curvature R(s) are given by

Expressions for calculating the curvature in arbitrary coordinate systems are given below.

lissajous-curve_nebeneinander_animated

lemniscate_nebeneinander_animated

Animations of the signed curvature and the acceleration vector T′(s)

Signed curvature

The sign of the signed curvature k indicates the direction in which the unit tangent vector rotates as a function of the parameter along the curve. If the unit tangent rotates counterclockwise, then k > 0. If it rotates clockwise, then k < 0. So, for example, the sign of the curvature of a graph is the same as the sign of the second derivative (see below).

The signed curvature depends on the particular parametrization chosen for a curve. For example, the unit circle can be parametrised by (cos θ, sin θ) (counterclockwise, with k > 0), or by (cos(−θ), sin(−θ)) (clockwise, with k < 0). More precisely, the signed curvature depends only on the choice of orientation of an immersed curve. Every immersed curve in the plane admits two possible orientations.

Local expressions

For a plane curve given parametrically in Cartesian coordinates as γ(t) = (x(t),y(t)), the curvature is

where primes refer to derivatives ddt with respect to the parameter t. The signed curvature k is

The expression reflects the geometric meaning discussed above, that the curvature is influenced by the change amount of the tangent vector in the direction of the normal vector, as

These can be expressed in a coordinate-independent manner via

 

然而『朝向』與『轉向角度』之計算,於  {90}^{\circ}{270}^{\circ}  時︰

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') >>>  >>> t = [math.pi/180*n for n in range(361)] >>> xc = [100*math.sin(t[n]) for n in range(361)]  >>> yc = [100*math.cos(t[n]) for n in range(361)] >>> 點距 = [math.sqrt( (yc[n+1]-yc[n])**2 + (xc[n+1]-xc[n])**2 ) for n in range(360)] >>> 朝向 = [90 - 180.0/math.pi*math.atan( (yc[n+1]-yc[n])/(xc[n+1]-xc[n]) ) for n in range(360)] >>> 轉向角度 = [朝向[n+1]-朝向[n] for n in range(359)]  >>>  >>> 朝向[88:92] [178.49999999999972, 179.5000000000002, 0.49999999999980105, 1.5000000000002984] >>> 朝向[268:272] [178.4999999999997, 179.50000000000017, 0.49999999999981526, 1.5000000000002416] >>> 轉向角度[88:91] [1.0000000000004832, -179.0000000000004, 1.0000000000004974] >>> 轉向角度[268:271] [1.0000000000004832, -179.00000000000034, 1.0000000000004263] >>>  </pre>    <span style="color: #003300;">可發生『垂直切線』的現象︰</span> <h1 id="firstHeading" class="firstHeading" lang="en"><span style="color: #ff9900;"><a style="color: #ff9900;" href="https://en.wikipedia.org/wiki/Vertical_tangent">Vertical tangent</a></span></h1> <span style="color: #808080;">In <a style="color: #808080;" title="Mathematics" href="https://en.wikipedia.org/wiki/Mathematics">mathematics</a>, particularly <a style="color: #808080;" title="Calculus" href="https://en.wikipedia.org/wiki/Calculus">calculus</a>, a <b>vertical tangent</b> is <a style="color: #808080;" title="Tangent" href="https://en.wikipedia.org/wiki/Tangent">tangent</a> line that is <a class="mw-redirect" style="color: #808080;" title="Vertical direction" href="https://en.wikipedia.org/wiki/Vertical_direction">vertical</a>. Because a vertical line has <a style="color: #808080;" title="Infinity" href="https://en.wikipedia.org/wiki/Infinity">infinite</a> <a style="color: #808080;" title="Slope" href="https://en.wikipedia.org/wiki/Slope">slope</a>, a <a style="color: #808080;" title="Function (mathematics)" href="https://en.wikipedia.org/wiki/Function_%28mathematics%29">function</a> whose <a style="color: #808080;" title="Graph of a function" href="https://en.wikipedia.org/wiki/Graph_of_a_function">graph</a> has a vertical tangent is not <a class="mw-redirect" style="color: #808080;" title="Differentiable" href="https://en.wikipedia.org/wiki/Differentiable">differentiable</a> at the point of tangency.</span>  <img class="alignnone size-full wp-image-64199" src="http://www.freesandal.org/wp-content/uploads/220px-Vertical_tangent.svg.png" alt="220px-vertical_tangent-svg" width="220" height="220" />  <span style="color: #999999;">Vertical tangent on the function <i>ƒ</i>(<i>x</i>) at <i>x</i>=<i>c</i>.</span> <h2><span id="Limit_definition" class="mw-headline" style="color: #808080;">Limit definition</span></h2> <span style="color: #808080;">A function ƒ has a vertical tangent at <i>x</i> = <i>a</i> if the <a style="color: #808080;" title="Difference quotient" href="https://en.wikipedia.org/wiki/Difference_quotient">difference quotient</a> used to define the derivative has infinite limit:</span> <dl>  	<dd><span style="color: #808080;"><img class="mwe-math-fallback-image-inline" src="https://wikimedia.org/api/rest_v1/media/math/render/svg/2ff14eccefe3fadabc0e34728e9e7eadadbf1f3b" alt="{\displaystyle \lim _{h\to 0}{\frac {f(a+h)-f(a)}{h}}={+\infty }\quad {\text{or}}\quad \lim _{h\to 0}{\frac {f(a+h)-f(a)}{h}}={-\infty }.}" /></span></dd> </dl> <span style="color: #808080;">The first case corresponds to an upward-sloping vertical tangent, and the second case to a downward-sloping vertical tangent. Informally speaking, the graph of ƒ has a vertical tangent at <i>x</i> = <i>a</i> if the derivative of ƒ at <i>a</i> is either positive or negative infinity.</span>  <span style="color: #808080;">For a <a style="color: #808080;" title="Continuous function" href="https://en.wikipedia.org/wiki/Continuous_function">continuous function</a>, it is often possible to detect a vertical tangent by taking the limit of the derivative. If</span> <dl>  	<dd><span style="color: #808080;"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y">  </span><img class="mwe-math-fallback-image-inline" src="https://wikimedia.org/api/rest_v1/media/math/render/svg/799c5460b8241f43cb1f289819ab12643933a45d" alt="{\displaystyle \lim _{x\to a}f'(x)={+\infty }{\text{,}}}" /></span></dd> </dl> <span style="color: #808080;">then ƒ must have an upward-sloping vertical tangent at <i>x</i> = <i>a</i>. Similarly, if</span> <dl>  	<dd><span style="color: #808080;"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y">  </span><img class="mwe-math-fallback-image-inline" src="https://wikimedia.org/api/rest_v1/media/math/render/svg/a34bd5502dcb3070a8bea07dd1ce488e1a861508" alt="{\displaystyle \lim _{x\to a}f'(x)={-\infty }{\text{,}}}" /></span></dd> </dl> <span style="color: #808080;">then ƒ must have a downward-sloping vertical tangent at <i>x</i> = <i>a</i>. In these situations, the vertical tangent to ƒ appears as a vertical <a style="color: #808080;" title="Asymptote" href="https://en.wikipedia.org/wiki/Asymptote">asymptote</a> on the graph of the derivative.</span> <h2><span id="Vertical_cusps" class="mw-headline" style="color: #808080;">Vertical cusps</span></h2> <span style="color: #808080;">Closely related to vertical tangents are <b>vertical <a style="color: #808080;" title="Cusp (singularity)" href="https://en.wikipedia.org/wiki/Cusp_%28singularity%29">cusps</a></b>. This occurs when the <a class="mw-redirect" style="color: #808080;" title="One-sided derivative" href="https://en.wikipedia.org/wiki/One-sided_derivative">one-sided derivatives</a> are both infinite, but one is positive and the other is negative. For example, if</span> <dl>  	<dd><span style="color: #808080;"><img class="mwe-math-fallback-image-inline" src="https://wikimedia.org/api/rest_v1/media/math/render/svg/87e708e66736947b293a4709e02812ea4ad76a04" alt="{\displaystyle \lim _{h\to 0^{-}}{\frac {f(a+h)-f(a)}{h}}={+\infty }\quad {\text{and}}\quad \lim _{h\to 0^{+}}{\frac {f(a+h)-f(a)}{h}}={-\infty }{\text{,}}}" /></span></dd> </dl> <span style="color: #808080;">then the graph of ƒ will have a vertical cusp that slopes up on the left side and down on the right side.</span>  <span style="color: #808080;">As with vertical tangents, vertical cusps can sometimes be detected for a continuous function by examining the limit of the derivative. For example, if</span> <dl>  	<dd><span style="color: #808080;"><img class="mwe-math-fallback-image-inline" src="https://wikimedia.org/api/rest_v1/media/math/render/svg/b9acea68a30c810a38deec397c4a2f9d2fd0282e" alt="{\displaystyle \lim _{x\to a^{-}}f'(x)={-\infty }\quad {\text{and}}\quad \lim _{x\to a^{+}}f'(x)={+\infty }{\text{,}}}" /></span></dd> </dl> <span style="color: #808080;">then the graph of ƒ will have a vertical cusp that slopes down on the left side and up on the right side. This corresponds to a vertical asymptote on the graph of the derivative that goes to  <img class="mwe-math-fallback-image-inline" src="https://wikimedia.org/api/rest_v1/media/math/render/svg/c26c105004f30c27aa7c2a9c601550a4183b1f21" alt="\infty " /> on the left and  <img class="mwe-math-fallback-image-inline" src="https://wikimedia.org/api/rest_v1/media/math/render/svg/ca2608c4b5fd3bffc73585f8c67e379b4e99b6f1" alt="-\infty " /> on the right.</span>     <span style="color: #003300;">『動點』之『參數曲線』恐有『尖點』奇異︰</span> <h1 id="firstHeading" class="firstHeading" lang="en"><span style="color: #ff9900;"><a style="color: #ff9900;" href="https://en.wikipedia.org/wiki/Cusp_%28singularity%29">Cusp (singularity)</a></span></h1> <span style="color: #ff9900;">In <a style="color: #ff9900;" title="Mathematics" href="https://en.wikipedia.org/wiki/Mathematics">mathematics</a> a <b>cusp</b>, sometimes called <b>spinode</b> in old texts, is a point on a curve where a moving point on the curve must start to move backward. A typical example is given in the figure. A cusp is thus a type of <a style="color: #ff9900;" title="Singular point of a curve" href="https://en.wikipedia.org/wiki/Singular_point_of_a_curve">singular point of a curve</a>.</span>  <span style="color: #808080;">For a <a style="color: #808080;" title="Plane curve" href="https://en.wikipedia.org/wiki/Plane_curve">plane curve</a> defined by a <a style="color: #808080;" title="Differentiable function" href="https://en.wikipedia.org/wiki/Differentiable_function">differentiable</a> <a style="color: #808080;" title="Parametric equation" href="https://en.wikipedia.org/wiki/Parametric_equation">parametric equation</a></span> <dl>  	<dd><span style="color: #808080;"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y">  </span><img class="mwe-math-fallback-image-inline" src="https://wikimedia.org/api/rest_v1/media/math/render/svg/827cbad7a1522066f5fdef309ce7c3d92aabd736" alt="" /></span></dd> </dl> <span style="color: #808080;">a cusp is a point where both <a style="color: #808080;" title="Derivative" href="https://en.wikipedia.org/wiki/Derivative">derivatives</a> of <span class="texhtml"><i>f</i></span> and <span class="texhtml"><i>g</i></span> are zero, and at least one of them changes sign. Cusps are <i>local singularities</i> in the sense that they involve only one value of the parameter <span class="texhtml"><i>t</i></span>, contrarily to self-intersection points that involve several values.</span>  <span style="color: #808080;">For a curve defined by an <a class="mw-redirect" style="color: #808080;" title="Implicit equation" href="https://en.wikipedia.org/wiki/Implicit_equation">implicit equation</a></span> <dl>  	<dd><span style="color: #808080;"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y">  </span><img class="mwe-math-fallback-image-inline" src="https://wikimedia.org/api/rest_v1/media/math/render/svg/23114792c399e36883fae6a06fcf7d34a3cb65e3" alt="F(x,y)=0," /></span></dd> </dl> <span style="color: #808080;">cusps are points where the terms of lowest degree of the <a class="mw-redirect" style="color: #808080;" title="Taylor expansion" href="https://en.wikipedia.org/wiki/Taylor_expansion">Taylor expansion</a> of <span class="texhtml"><i>F</i></span> are a power of a <a class="mw-redirect" style="color: #808080;" title="Linear polynomial" href="https://en.wikipedia.org/wiki/Linear_polynomial">linear polynomial</a>; however not all singular points that have this property are cusps. In some contexts, and in the remainder of this article, one restricts the definition of a cusp to the case where the non-zero part of lowest degree of the Taylor expansion of <span class="texhtml"><i>F</i></span> has degree two.</span>  <span style="color: #808080;">A <a style="color: #808080;" title="Plane curve" href="https://en.wikipedia.org/wiki/Plane_curve">plane curve</a> cusp may be put in one of the following forms by a <a style="color: #808080;" title="Diffeomorphism" href="https://en.wikipedia.org/wiki/Diffeomorphism">diffeomorphism</a> of the plane: <i>x</i><sup>2</sup> − <i>y</i><sup>2<i>k</i>+1</sup> = 0, where <i>k</i> \ge  1 is an <a style="color: #808080;" title="Integer" href="https://en.wikipedia.org/wiki/Integer">integer</a>.</span>  <img class="alignnone size-full wp-image-64202" src="http://www.freesandal.org/wp-content/uploads/200px-Cusp.svg.png" alt="200px-cusp-svg" width="200" height="261" />  <span style="color: #999999;">An ordinary cusp on the curve <i>x</i><sup>3</sup>-<i>y</i><sup>2</sup>=0</span>     <span style="color: #003300;">故需審慎對待乎??此所以『圓難畫』、『心難知』耶!!</span> <pre class="lang:python decode:true">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')
>>> 
>>> t = [math.pi/180*n for n in range(361)]
>>> xc = [100*math.sin(t[n]) for n in range(361)] 
>>> yc = [100*math.cos(t[n]) for n in range(361)]
>>> 點距 = [math.sqrt( (yc[n+1]-yc[n])**2 + (xc[n+1]-xc[n])**2 ) for n in range(360)]
>>> 朝向 = [90 - 180.0/math.pi*math.atan( (yc[n+1]-yc[n])/(xc[n+1]-xc[n]) ) for n in range(360)]
>>> 轉向角度 = [朝向[n+1]-朝向[n] for n in range(359)] 
>>> 
>>> 朝向[88:92]
[178.49999999999972, 179.5000000000002, 0.49999999999980105, 1.5000000000002984]
>>> 朝向[268:272]
[178.4999999999997, 179.50000000000017, 0.49999999999981526, 1.5000000000002416]
>>> 轉向角度[88:91]
[1.0000000000004832, -179.0000000000004, 1.0000000000004974]
>>> 轉向角度[268:271]
[1.0000000000004832, -179.00000000000034, 1.0000000000004263]
>>> 
>>> 起始角度 = 朝向[0]
>>> 第一步長度 = 點距[0]
>>> 餘步列 = 點距[1:]
>>> 
>>> 轉向角度[89] = 轉向角度[88]
>>> 轉向角度[269] = 轉向角度[268]
>>> 轉向角度[88:91]
[1.0000000000004832, 1.0000000000004832, 1.0000000000004974]
>>> 轉向角度[268:271]
[1.0000000000004832, 1.0000000000004832, 1.0000000000004263]
>>> 
>>> def 畫圓():
...     保存原向 = turtle.heading()
...     turtle.right(起始角度)
...     turtle.forward(第一步長度)
...     for n in range(359):
...         if 轉向角度[n] > 0:
...             turtle.right(轉向角度[n])
...         else:
...             turtle.left(-轉向角度[n])
...         turtle.forward(餘步列[n])
...     turtle.seth(保存原向)
... 
>>> 畫圓()
>>> 
>>> x = [80*math.sin(t[n])**3 for n in range(361)]
>>> y = [65*math.cos(t[n])- 25*math.cos(2*t[n])-10*math.cos(3*t[n])-5*math.cos(4*t[n]) for n in range(361)]
>>> 點距 = [math.sqrt( (y[n+1]-y[n])**2 + (x[n+1]-x[n])**2 ) for n in range(360)]
>>> 朝向 = [90 - 180.0/math.pi*math.atan( (y[n+1]-y[n])/(x[n+1]-x[n]) ) for n in range(360)]
>>> 轉向角度 = [朝向[n+1]-朝向[n] for n in range(359)]
>>> 轉向角度[88:91]
[2.541118754282593, -177.4740814826926, 2.5038729840123324]
>>> 轉向角度[268:271]
[2.503872984012361, -177.47408148269255, 2.5411187542823797]
>>> 轉向角度[89] = 轉向角度[88]
>>> 轉向角度[269] = 轉向角度[268]
>>> 
>>> def 知心():
...     保存原向 = turtle.heading()
...     turtle.right(起始角度)
...     turtle.forward(第一步長度)
...     for n in range(359):
...         if 轉向角度[n] > 0:
...             turtle.right(轉向角度[n])
...         else:
...             turtle.left(-轉向角度[n])
...         turtle.forward(餘步列[n])
...     turtle.seth(保存原向)
... 
>>> 
# 自光明
>>> turtle.reset();turtle.color('red', 'yellow');turtle.begin_fill();知心();turtle.end_fill()
>>> 

 

【畫圓】

python-turtle-graphics_%e7%9f%a5%e5%bf%83

 

【知心】

python-turtle-graphics_125

 

【自光明】

python-turtle-graphics_%e8%87%aa%e5%85%89%e6%98%8e

 

 勒☆