光的世界︰派生科學計算六‧下

廬山東林寺三笑庭名聯‧清‧唐蝸寄

橋跨虎溪,三教三源流,三人三笑語;
蓮開僧舍,一花一世界,一葉一如來。

曾經三人三笑語,聞得虎嘯,恍然大悟。何故三詠三抒懷︰

詠二疏‧陶淵明

大象轉四時,功成者自去。
借問衰周來,幾人得其趣?
遊目漢廷中,二疏復此舉。
高嘯返舊居,長揖儲君傅。
餞送傾皇朝,華軒盈道路。
離別情所悲,余榮何足顧!
事勝感行人,賢哉豈常譽?
厭厭閭裏歡,所營非近務。
促席延故老,揮觴道平素。
問金終寄心,清言曉未悟。
放意樂餘年,遑恤身後慮。
誰雲其人亡,久而道彌著。

詠三良‧陶淵明

彈冠乘通津,但懼時我遺;
服勤盡歲月,常恐功愈微。
忠情謬獲露,遂為君所私。
出則陪文輿,入必侍丹帷;
箴規向已從,計議初無虧。
一朝長逝後,願言同此歸。
厚恩因難忘,君命安可違?
臨穴罔惟疑,投義誌攸希。
荊棘籠高墳,黃鳥聲正悲。
良人不可贖,泫然沾我衣。

詠荊軻‧陶淵明

燕丹善養士,誌在報強嬴。
招集百夫良,歲暮得荊卿。
君子死知己,提劍出燕京;
素驥鳴廣陌,慷慨送我行。
雄發指危冠,猛氣衝長纓。
飲餞易水上,四座列群英。
漸離擊悲筑,宋意唱高聲。
蕭蕭哀風逝,淡淡寒波生。
商音更流涕,羽奏壯士驚。
心知去不歸,且有後世名。
登車何時顧,飛蓋入秦庭。
淩厲越萬裏,逶迤過千城。
圖窮事自至,豪主正怔營。
惜哉劍術疏,奇功遂不成!
其人雖已沒,千載有餘情。

晉時淵明,晉後名潛,已棄五斗米,不知姓字忘其何人,五柳先生『伍』『柳』吟誦耶??果真二三子其志一也!!雖說是移時隔空得失不同,其人其心何其相似乎??!!先生『菀柳』之『情』仍一樣吧!!??

誰雲其人亡,久而道彌著。

良人不可贖,泫然沾我衣。

其人雖已沒,千載有餘情。

大暑已過,入秋之際,講此『春耕夏耘』之『心法』勒。古今中外『學問』縱有千百種,談起功夫『心法』則一矣。往往其『志一』其『人同』也!!只是『一花』『一葉』真誠對待歟??

如果天地公平,天理能隨觀者變乎??故知物理學之所以著意於

仿射變換性質了!!

一仿射變換保留了:

  1. 點之間的共線性,例如通過同一線之點 (即稱為共線點)在變換後仍呈共線。
  2. 向量沿著一線的比例,例如對相異共線三點 p_{1},\,p_{2},\,p_{3}, \overrightarrow {p_{1}p_{2}}\overrightarrow {p_{2}p_{3}}的比例同於 \overrightarrow {f(p_{1})f(p_{2})}  \overrightarrow {f(p_{2})f(p_{3})}
  3. 帶不同質量的點之質心

一仿射變換為可逆的若且唯若A為可逆的。在矩陣表示中,其反元素為

{\begin{bmatrix}A^{{-1}}&-A^{{-1}}{\vec {b}}\ \\0,\ldots ,0&1\end{bmatrix}}

可逆仿射變換組成仿射群,其中包含具n階的一般線性群為子群,且自身亦為一n+1階的一般線性群之子群。 當A為常數乘以正交矩陣時,此子集合構成一子群,稱之為相似變換舉例而言,假如仿射變換於一平面上且假如A之行列式為1或-1,那麼該變換即為等面積變換。此類變換組成一稱為等仿射群的子集。一同時為等面積變換與相似變換之變換,即為一平面上保持歐幾里德距離不變之保距映射 這些群都有一保留了原定向的子群,也就是其對應之A的行列式大於零。在最後一例中,即為三維中剛體運動之群(旋轉加平移)。 假如有一不動點,我們可以將其當成原點,則仿射變換被縮還到一線性變換。這使得變換更易於分類與理解。舉例而言,將一變換敘述為特定軸的旋轉,相較於將其形容為平移與旋轉的結合,更能提供變換行為清楚的解釋。只是,這取決於應用與內容。

 

若知『平移』與『旋轉』為『保距映射』,餘理可知矣︰

※矩陣乘法不具『交換性』,正是『平移』後『旋轉』往往不等於『旋轉』再『平移』也。

pi@raspberrypi:~ ipython3 Python 3.4.2 (default, Oct 19 2014, 13:31:11)  Type "copyright", "credits" or "license" for more information.  IPython 2.3.0 -- An enhanced Interactive Python. ?         -> Introduction and overview of IPython's features. %quickref -> Quick reference. help      -> Python's own help system. object?   -> Details about 'object', use 'object??' for extra details.  In [1]: from sympy import *  In [2]: init_printing()  In [3]: xα, yα, xβ, yβ, Tx, Ty, θ = symbols('xα, yα, xβ, yβ, Tx, Ty, θ')  In [4]: T = Matrix([[1, 0, Tx], [0, 1, Ty], [0, 0, 1]])  In [5]: T Out[5]:  ⎡1  0  Tx⎤ ⎢        ⎥ ⎢0  1  Ty⎥ ⎢        ⎥ ⎣0  0  1 ⎦  In [6]: T.det() Out[6]: 1  In [7]: R = Matrix([[cos(θ), sin(θ), 0], [-sin(θ), cos(θ), 0], [0, 0, 1]])  In [8]: R Out[8]:  ⎡cos(θ)   sin(θ)  0⎤ ⎢                  ⎥ ⎢-sin(θ)  cos(θ)  0⎥ ⎢                  ⎥ ⎣   0       0     1⎦  In [9]: R.det() Out[9]:     2         2    sin (θ) + cos (θ)  In [10]: R.det().simplify() Out[10]: 1  In [11]: α平移 = T * Matrix([xα, yα, 1])  In [12]: α平移 Out[12]:  ⎡Tx + xα⎤ ⎢       ⎥ ⎢Ty + yα⎥ ⎢       ⎥ ⎣   1   ⎦  In [13]: β平移 = T * Matrix([xβ, yβ, 1])  In [14]:  β平移 Out[14]:  ⎡Tx + xβ⎤ ⎢       ⎥ ⎢Ty + yβ⎥ ⎢       ⎥ ⎣   1   ⎦  In [15]: αβ平移距離 = (α平移[0] - β平移[0])** 2 + (α平移[1] - β平移[1])** 2  In [16]: αβ平移距離 Out[16]:           2            2 (xα - xβ)  + (yα - yβ)   In [17]: α旋轉 = R * Matrix([xα, yα, 1])  In [18]: α旋轉 Out[18]:  ⎡xα⋅cos(θ) + yα⋅sin(θ) ⎤ ⎢                      ⎥ ⎢-xα⋅sin(θ) + yα⋅cos(θ)⎥ ⎢                      ⎥ ⎣          1           ⎦  In [19]: β旋轉 = R * Matrix([xβ, yβ, 1])  In [20]: β旋轉 Out[20]:  ⎡xβ⋅cos(θ) + yβ⋅sin(θ) ⎤ ⎢                      ⎥ ⎢-xβ⋅sin(θ) + yβ⋅cos(θ)⎥ ⎢                      ⎥ ⎣          1           ⎦  In [21]: αβ旋轉距離 = (α旋轉[0] - β旋轉[0])** 2 + (α旋轉[1] - β旋轉[1])** 2  In [22]: αβ旋轉距離 Out[22]:                                                  2                              (-xα⋅sin(θ) + xβ⋅sin(θ) + yα⋅cos(θ) - yβ⋅cos(θ))  + (xα⋅cos(θ) - xβ⋅cos(θ) + y                       2 α⋅sin(θ) - yβ⋅sin(θ))   In [23]: αβ旋轉距離.expand().simplify() Out[23]:    2               2     2               2 xα  - 2⋅xα⋅xβ + xβ  + yα  - 2⋅yα⋅yβ + yβ   In [24]: R*T Out[24]:  ⎡cos(θ)   sin(θ)  Tx⋅cos(θ) + Ty⋅sin(θ) ⎤ ⎢                                       ⎥ ⎢-sin(θ)  cos(θ)  -Tx⋅sin(θ) + Ty⋅cos(θ)⎥ ⎢                                       ⎥ ⎣   0       0               1           ⎦  In [25]: T*R Out[25]:  ⎡cos(θ)   sin(θ)  Tx⎤ ⎢                   ⎥ ⎢-sin(θ)  cos(θ)  Ty⎥ ⎢                   ⎥ ⎣   0       0     1 ⎦  In [26]:  </pre>    <span style="color: #003300;">光有『心法』,缺少『運用』之實務修煉,功夫怕也不踏實。在此祇以『相似幾何』之理</span> <h1 id="firstHeading" class="firstHeading" lang="en"><span style="color: #003300;"><a style="color: #003300;" href="https://en.wikipedia.org/wiki/Similarity_%28geometry%29">Similarity (geometry)</a></span></h1> <span style="color: #808080;">Two geometrical objects are called <b>similar</b> if they both have the same <a style="color: #808080;" title="Shape" href="https://en.wikipedia.org/wiki/Shape">shape</a>, or one has the same shape as the mirror image of the other. More precisely, one can be obtained from the other by uniformly <a style="color: #808080;" title="Scaling (geometry)" href="https://en.wikipedia.org/wiki/Scaling_%28geometry%29">scaling</a> (enlarging or shrinking), possibly with additional <a style="color: #808080;" title="Translation (geometry)" href="https://en.wikipedia.org/wiki/Translation_%28geometry%29">translation</a>, <a style="color: #808080;" title="Rotation (mathematics)" href="https://en.wikipedia.org/wiki/Rotation_%28mathematics%29">rotation</a> and <a style="color: #808080;" title="Reflection (mathematics)" href="https://en.wikipedia.org/wiki/Reflection_%28mathematics%29">reflection</a>. This means that either object can be rescaled, repositioned, and reflected, so as to coincide precisely with the other object. If two objects are similar, each is <a style="color: #808080;" title="Congruence (geometry)" href="https://en.wikipedia.org/wiki/Congruence_%28geometry%29">congruent</a> to the result of a particular uniform scaling of the other. A modern and novel perspective of similarity is to consider geometrical objects similar if one appears congruent to the other when zoomed in or out at some level.</span>  <span style="color: #808080;">For example, all <a style="color: #808080;" title="Circle" href="https://en.wikipedia.org/wiki/Circle">circles</a> are similar to each other, all <a class="mw-redirect" style="color: #808080;" title="Square (geometry)" href="https://en.wikipedia.org/wiki/Square_%28geometry%29">squares</a> are similar to each other, and all <a class="mw-redirect" style="color: #808080;" title="Equilateral triangles" href="https://en.wikipedia.org/wiki/Equilateral_triangles">equilateral triangles</a> are similar to each other. On the other hand, <a style="color: #808080;" title="Ellipse" href="https://en.wikipedia.org/wiki/Ellipse">ellipses</a> are <i>not</i> all similar to each other, <a class="mw-redirect" style="color: #808080;" title="Rectangles" href="https://en.wikipedia.org/wiki/Rectangles">rectangles</a> are not all similar to each other, and <a style="color: #808080;" title="Isosceles triangle" href="https://en.wikipedia.org/wiki/Isosceles_triangle">isosceles triangles</a> are not all similar to each other.</span>  <span style="color: #808080;">If two angles of a triangle have measures equal to the measures of two angles of another triangle, then the triangles are similar. Corresponding sides of similar polygons are in proportion, and corresponding angles of similar polygons have the same measure.</span>  <span style="color: #808080;">This article assumes that a scaling can have a scale factor of 1, so that all congruent shapes are also similar, but some school text books specifically exclude congruent triangles from their definition of similar triangles by insisting that the sizes must be different if the triangles are to qualify as similar.</span>  <img class="alignnone size-full wp-image-56737" src="http://www.freesandal.org/wp-content/uploads/300px-Similar-geometric-shapes.svg.png" alt="300px-Similar-geometric-shapes.svg" width="300" height="208" />  <span style="color: #808080;">Figures shown in the same color are similar</span>     <span style="color: #003300;">介紹一下『skimage』程式庫</span>  <img class="alignnone size-full wp-image-56740" src="http://www.freesandal.org/wp-content/uploads/skimagelogo.png" alt="skimagelogo" width="568" height="140" /> <div class="well hero row-fluid summary-box container"> <h2><span style="color: #808080;"><a style="color: #808080;" href="http://scikit-image.org/">Image processing in Python</a></span></h2> <span style="color: #808080;"><em>scikit-image</em> is a collection of algorithms for image processing. It is available <a class="reference external" style="color: #808080;" href="http://scikit-image.org/docs/dev/license.html">free of charge and free of restriction</a>. We pride ourselves on high-quality, peer-reviewed code, written by an active <a class="reference external" style="color: #808080;" href="https://www.ohloh.net/p/scikit-image/contributors">community of volunteers</a>.</span>  <span style="color: #808080;"><a class="btn btn-warning clearfix" style="color: #808080;" href="http://scikit-image.org/download"> <i class="icon-download icon-white"></i>Download</a></span>  </div> <div id="getting-started" class="section"> <h1><span style="color: #808080;">Getting Started</span></h1> <span style="color: #808080;">Filtering an image with <code class="docutils literal"><span class="pre">scikit-image</span></code> is easy! For more examples, please visit our <a class="reference external" style="color: #808080;" href="http://scikit-image.org/docs/dev/auto_examples">gallery</a>.</span> <pre class="lang:python decode:true ">from skimage import data, io, filters  image = data.coins() # or any NumPy array! edges = filters.sobel(image) io.imshow(edges) io.show() </pre> <div class="row-fluid container"> <div class="well span6 container"><img class="coins-sample span6" src="http://scikit-image.org/_images/coins-small.png" alt="_images/coins-small.png" /> <img class="coins-sample span6" src="http://scikit-image.org/_images/sobel-coins-small.png" alt="_images/sobel-coins-small.png" /></div> </div> <div class="well hero row-fluid summary-box citation container">  <span style="color: #808080;"><b>If you find this project useful, please cite:</b> [<a style="color: #808080;" href="http://scikit-image.org/_static/skimage.bib">BiBTeX</a>]</span>  <span style="color: #808080;">Stéfan van der Walt, Johannes L. Schönberger, Juan Nunez-Iglesias, François Boulogne, Joshua D. Warner, Neil Yager, Emmanuelle Gouillart, Tony Yu and the scikit-image contributors. <b>scikit-image: Image processing in Python</b>. PeerJ 2:e453 (2014) <a style="color: #808080;" href="http://dx.doi.org/10.7717/peerj.453"> http://dx.doi.org/10.7717/peerj.453 </a></span>  </div> </div>    <span style="color: #003300;">在二維圖像上的應用,且當個門徑吧。</span>  <span style="color: #808080;">【參考資料】</span>  <span style="color: #808080;">‧ <a style="color: #808080;" href="http://scikit-image.org/docs/dev/auto_examples/applications/plot_geometric.html">Using geometric transformations</a></span>  <span style="color: #808080;">‧ <a style="color: #808080;" href="http://scikit-image.org/docs/dev/api/skimage.transform.html">Module: transform</a></span>  <span style="color: #808080;">‧ <a style="color: #808080;" href="http://www.ncbi.nlm.nih.gov/pmc/articles/PMC4081273/">scikit-image: image processing in Python</a></span>  <span style="color: #808080;">‧ <a style="color: #808080;" href="http://www.scipy-lectures.org/packages/scikit-image/">Scikit-image: image processing</a></span>     <span style="color: #003300;">讀者切莫因五行程式範例文字儼然『校對有誤』就止步!</span> <pre class="lang:python decode:true">pi@raspberrypi:~ ipython3
Python 3.4.2 (default, Oct 19 2014, 13:31:11) 
Type "copyright", "credits" or "license" for more information.

IPython 2.3.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: from skimage import data, io, filter

In [2]: image = data.coins()

In [3]: edges = filter.sobel(image)

In [4]: io.imshow(edges)

In [5]: io.show()

In [6]: io.imshow(image)

In [7]: io.show()

In [8]: 文本 = data.text()

 

skimage_filter_1

 

skimage_filter_2

 

須知積極更新發展快速之程式庫,文件往往可能『前差後異』也?

In [9]: from skimage import transform as tf

In [10]: 旋轉文本 = tf.rotate(文本, 45, resize=True)

In [11]: io.imshow(文本)

In [12]: io.show()

In [13]: io.imshow(旋轉文本)

In [14]: io.show()

In [15]: import math

In [16]: 相似變換 = tf.SimilarityTransform( rotation=math.pi / 4, translation=( 文本.sape[0] / 2, -100))

In [17]: 相似變換文本 = tf.warp(文本, 相似變換)

In [18]: io.imshow(相似變換文本)

In [19]: io.show()

In [20]: 

 

skimage_文本

 

skimage_文本旋轉

 

skimage_文本相似變換

 

難到山不會轉,竟然路也不能轉耶??!!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

光的世界︰派生科學計算六‧中

歐式幾何裡並無『座標系』之概念,而是以『全等』關係︰

Congruence (geometry)

In geometry, two figures or objects are congruent if they have the same shape and size, or if one has the same shape and size as the mirror image of the other.[1]

More formally, two sets of points are called congruent if, and only if, one can be transformed into the other by an isometry, i.e., a combination of rigid motions, namely a translation, a rotation, and a reflection. This means that either object can be repositioned and reflected (but not resized) so as to coincide precisely with the other object. So two distinct plane figures on a piece of paper are congruent if we can cut them out and then match them up completely. Turning the paper over is permitted.

In elementary geometry the word congruent is often used as follows.[2] The word equal is often used in place of congruent for these objects.

  • Two line segments are congruent if they have the same length.
  • Two angles are congruent if they have the same measure.
  • Two circles are congruent if they have the same diameter.

In this sense, two plane figures are congruent implies that their corresponding characteristics are “congruent” or “equal” including not just their corresponding sides and angles, but also their corresponding diagonals, perimeters and areas.

The related concept of similarity applies if the objects differ in size but not in shape.

Congruent_non-congruent_triangles.svg

An example of congruence. The two triangles on the left are congruent, while the third is similar to them. The last triangle is neither similar nor congruent to any of the others. Note that congruence permits alteration of some properties, such as location and orientation, but leaves others unchanged, like distance and angles. The unchanged properties are called invariants.

 

研究各類圖形具有種種性質之『不變性』。

參照之前文本所說︰

……

從物理上講,那個三角形就是『剛體』 rigid body ,它在『運動』中保持『形狀』的『不變性』。而且不同觀察者間的『座標變換』可以用

Rigid transformation

In mathematics, a rigid transformation (isometry) of a vector space preserves distances between every pair of points.[1][2] Rigid transformations of the plane R2, space R3, or real n-dimensional space Rn are termed a Euclidean transformation because they form the basis of Euclidean geometry.[3]

The rigid transformations include rotations, translations, reflections, or their combination. Sometimes reflections are excluded from the definition of a rigid transformation by imposing that the transformation also preserve the handedness of figures in the Euclidean space (a reflection would not preserve handedness; for instance, it would transform a left hand into a right hand). To avoid ambiguity, this smaller class of transformations is known as proper rigid transformations (informally, also known as roto-translations). In general, any proper rigid transformation can be decomposed as a rotation followed by a translation, while any rigid transformation can be decomposed as an improper rotation followed by a translation (or as a sequence of reflections).

Any object will keep the same shape and size after a proper rigid transformation.

All rigid transformations are examples of affine transformations. The set of all (proper and improper) rigid transformations is a group called the Euclidean group, denoted E(n) for n-dimensional Euclidean spaces. The set of proper rigid transformation is called special Euclidean group, denoted SE(n).

In kinematics, proper rigid transformations in a 3-dimensional Euclidean space, denoted SE(3), are used to represent the linear and angular displacement of rigid bodies. According to Chasles’ theorem, every rigid transformation can be expressed as a screw displacement.

Formal definition

A rigid transformation is formally defined as a transformation that, when acting on any vector v, produces a transformed vector T(v) of the form

T(v) = R v + t

where RT = R−1 (i.e., R is an orthogonal transformation), and t is a vector giving the translation of the origin.

A proper rigid transformation has, in addition,

det(R) = 1

which means that R does not produce a reflection, and hence it represents a rotation (an orientation-preserving orthogonal transformation). Indeed, when an orthogonal transformation matrix produces a reflection, its determinant is –1.

Distance formula

A measure of distance between points, or metric, is needed in order to confirm that a transformation is rigid. The Euclidean distance formula for Rn is the generalization of the Pythagorean theorem. The formula gives the distance squared between two points X and Y as the sum of the squares of the distances along the coordinate axes, that is

 d(\mathbf{X},\mathbf{Y})^2 = (X_1-Y_1)^2 + (X_2-Y_2)^2 + \ldots + (X_n-Y_n)^2 = (\mathbf{X}-\mathbf{Y})\cdot(\mathbf{X}-\mathbf{Y}).

where X=(X1, X2, …, Xn) and Y=(Y1, Y2, …, Yn), and the dot denotes the scalar product.

Using this distance formula, a rigid transformation g:Rn→Rn has the property,

d(g(\mathbf{X}), g(\mathbf{Y}))^2 = d(\mathbf{X}, \mathbf{Y})^2.

─── 摘自《勇闖新世界︰ W!o《卡夫卡村》變形祭︰品味科學‧教具教材‧【專題】 PD‧箱子世界‧留白

 

如果依據伽利略『相對性』原理之視角,那麼物理性質也不該因為『觀察者』或『座標系』之不同而有所改變??因是古典力學就得符合『伽利略變換』矣!!

Galilean transformation

In physics, a Galilean transformation is used to transform between the coordinates of two reference frames which differ only by constant relative motion within the constructs of Newtonian physics. These transformations together with spatial rotations and translations in space and time form the inhomogeneous Galilean group (assumed throughout below). Without the translations in space and time the group is the homogeneous Galilean group. The Galilean group is the group of motions of Galilean relativity action on the four dimensions of space and time, forming the Galilean geometry. This is the passive transformation point of view. The equations below, although apparently obvious, are valid only at speeds much less than the speed of light. In special relativity the Galilean transformations are replaced by Poincaré transformations; conversely, the group contraction in the classical limit c → ∞ of Poincaré transformations yields Galilean transformations.

Galileo formulated these concepts in his description of uniform motion.[1] The topic was motivated by his description of the motion of a ball rolling down a ramp, by which he measured the numerical value for the acceleration of gravity near the surface of the Earth.

300px-Standard_conf

Standard configuration of coordinate systems for Galilean transformations.

 

只是通常各自有『原點』的『座標系』並不方便以『矩陣』來表達『時空』之『等距同構

Isometry

In mathematics, an isometry (or congruence, or congruent transformation) is a distance-preserving injective map between metric spaces.[1]

Introduction

Given a metric space (loosely, a set and a scheme for assigning distances between elements of the set), an isometry is a transformation which maps elements to the same or another metric space such that the distance between the image elements in the new metric space is equal to the distance between the elements in the original metric space. In a two-dimensional or three-dimensional Euclidean space, two geometric figures are congruent if they are related by an isometry;[3] the isometry that relates them is either a rigid motion (translation or rotation), or a composition of a rigid motion and a reflection.

Isometries are often used in constructions where one space is embedded in another space. For instance, the completion of a metric space M involves an isometry from M into M’, a quotient set of the space of Cauchy sequences on M. The original space M is thus isometrically isomorphic to a subspace of a complete metric space, and it is usually identified with this subspace. Other embedding constructions show that every metric space is isometrically isomorphic to a closed subset of some normed vector space and that every complete metric space is isometrically isomorphic to a closed subset of some Banach space.

An isometric surjective linear operator on a Hilbert space is called a unitary operator.

Academ_Reflections_with_parallel_axis_on_wallpaper.svg

A composition of two opposite isometries is a direct isometry. A reflection in a line is an opposite isometry, like R 1 or R 2 on the image. Translation T is a direct isometry: a rigid motion.[2]

 

的變換性質,因此借著

齊次坐標

數學裡,齊次坐標(homogeneous coordinates),或投影坐標(projective coordinates)是指一個用於投影幾何裡的坐標系統,如同用於歐氏幾何裡的笛卡兒坐標一般。該詞由奧古斯特·費迪南德·莫比烏斯於1827年在其著作《Der barycentrische Calcul》一書內引入[1][2]。齊次坐標可讓包括無窮遠點的點坐標以有限坐標表示。使用齊次坐標的公式通常會比用笛卡兒坐標表示更為簡單,且更為對稱 。齊次坐標有著廣泛的應用,包括電腦圖形及3D電腦視覺。使用齊次坐標可讓電腦進行仿射變換,並通常,其投影變換能簡單地使用矩陣來表示。

如一個點的齊次坐標乘上一個非零純量,則所得之坐標會表示同一個點。因為齊次坐標也用來表示無窮遠點,為此一擴展而需用來標示坐標之數值比投影空間之維度多一。例如,在齊次坐標裡,需要兩個值來表示在投影線上的一點,需要三個值來表示投影平面上的一點。

600px-RationalBezier2D.svg

有理貝茲曲線-定義於齊次坐標內的多項式曲線(藍色),以及於平面上的投影-有理曲線(紅色)

 

來統整論述也就自然而然的了??!!更別說由於雙眼之視覺現象還得走入『仿射變換』的哩!!??

 

2D_affine_transformation_matrix.svg

 

 

 

 

 

 

 

 

 

 

 

 

 

光的世界︰派生科學計算六‧上

過去我們曾經談過伽利略變換︰

如果從『伽利略變換』如何『觀察』這個『相對性』的意義的呢?假設以『□觀察者(x_{\Box}, t_{\Box}) 為『靜止』,『□觀察者』見『○觀察者(x_{\bigcirc}, t_{\bigcirc}) 以『速度v 向右運動,假使他們彼此能『交換資訊』,同意兩者的『原點』相同,那麼他們對『時空現象』或者說『事件』的『位置‧時間』描述滿足

\begin{bmatrix} x_{\bigcirc} \\ t_{\bigcirc} \end{bmatrix} = G_v \begin{bmatrix} x_{\Box} \\ t_{\Box} \end{bmatrix} = \begin{pmatrix} 1 & -v \\0 & 1 \end{pmatrix} \begin{bmatrix} x_{\Box} \\ t_{\Box} \end{bmatrix}

。『□觀察者』的『原點(0, t_{\Box}) 對『□觀察者』是『靜止』的,然而對『○觀察者』而言,是 x_{\bigcirc} = - v \cdot t_{\Box}t_{\bigcirc} = t_{\Box} ,它以『速度v等速向左』 運動。其次對於『□觀察者』而言,所發生的『同時兩事件(x_{\Box}^1, t_{\Box})  與 (x_{\Box}^2, t_{\Box}) ,對『○觀察者』而言,是 (x_{\Box}^1 - v \cdot t_{\Box}, t_{\Box})(x_{\Box}^2 - v \cdot t_{\Box}, t_{\Box}) 也是『同時的』。既然『運動是相對的』,假使我們以『○觀察者』為『靜止』,來作個『伽利略變換』的『物理檢驗』, 那麼 \begin{bmatrix} x_{\Box} \\ t_{\Box} \end{bmatrix} = G_{-v} \begin{bmatrix} x_{\bigcirc} \\ t_{\bigcirc} \end{bmatrix} 當是應該的了。也就是說 G_{-v} = {G_v}^{-1} = \begin{pmatrix} 1 & v \\0 & 1 \end{pmatrix},讀者自己可以『確證\begin{pmatrix} 1 & v \\0 & 1 \end{pmatrix} \times \begin{pmatrix} 1 & - v \\0 & 1 \end{pmatrix} = \begin{pmatrix} 1 & - v \\0 & 1 \end{pmatrix} \times \begin{pmatrix} 1 & v \\0 & 1 \end{pmatrix} = \begin{pmatrix} 1 & 0 \\0 & 1 \end{pmatrix} 它的『正確性』。也可以說『物理之要求』不得不決定了『數學的表達式』的吧!,所謂的『自然律』並不『必須』要『滿足』這種或那種『數學』的耶!!如果說『○觀察者』觀測某一個『星辰(x_{\star}, t_{\star})w 的『速度』向右『直線運動』,那麼這一個『星辰』相對於『□觀察者』的『速度』是什麼的呢?『直覺上』我們認為既然『★ 對 ○ 是 w 向右,○ 對 □ 是 v 向右』,那麼『★ 對 ○ 該是 w + v 向右』的吧!我們可以用『伽利略變換』計算如下

\begin{bmatrix} x_{\bigcirc} \\ t_{\bigcirc} \end{bmatrix} = G_v \begin{bmatrix} x_{\Box} \\ t_{\Box} \end{bmatrix} = \begin{pmatrix} 1 & -v \\0 & 1 \end{pmatrix} \begin{bmatrix} x_{\Box} \\ t_{\Box} \end{bmatrix}

\begin{bmatrix} x_{\star} \\ t_{\star} \end{bmatrix} = G_w \begin{bmatrix} x_{\bigcirc} \\ t_{\bigcirc} \end{bmatrix} = \begin{pmatrix} 1 & -w \\0 & 1 \end{pmatrix} \begin{bmatrix} x_{\bigcirc} \\ t_{\bigcirc} \end{bmatrix}

=  \begin{pmatrix} 1 & -w \\0 & 1 \end{pmatrix} \times \begin{pmatrix} 1 & -v \\0 & 1 \end{pmatrix} \begin{bmatrix} x_{\Box} \\ t_{\Box} \end{bmatrix}

=  \begin{pmatrix} 1 & -(w+v) \\0 & 1 \end{pmatrix} \begin{bmatrix} x_{\Box} \\ t_{\Box} \end{bmatrix}

=  G_{(w+v)} \begin{bmatrix} x_{\Box} \\ t_{\Box} \end{bmatrix}

,果真是『符合直覺』的勒!!

─── 摘自《【Sonic π】電聲學之電路學《四》之《 !!!! 》下

 

現今如果使用符號運算作回顧︰

pi@raspberrypi:~ 
*** QuickLaTeX cannot compile formula:
ipython3
Python 3.4.2 (default, Oct 19 2014, 13:31:11) 
Type "copyright", "credits" or "license" for more information.

IPython 2.3.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: from sympy import *

In [2]: init_printing()

In [3]: xα, xβ, xγ, yα, yβ, yγ, v, w = symbols('xα, xβ, xγ, yα, yβ, yγ, v, w')

In [4]: 伽利略變換 = Matrix([[1, -v], [0, 1]])

In [5]: 伽利略變換
Out[5]: 
⎡1  -v⎤
⎢     ⎥
⎣0  1 ⎦

In [6]: 伽利略變換.inv()
Out[6]: 
⎡1  v⎤
⎢    ⎥
⎣0  1⎦

In [7]: 伽利略變換.det()
Out[7]: 1

In [8]: 伽利略變換.inv().det()
Out[8]: 1

In [9]: G = Matrix([[1, -w], [0, 1]])

In [10]: G
Out[10]: 
⎡1  -w⎤
⎢     ⎥
⎣0  1 ⎦

In [11]: G * 伽利略變換
Out[11]: 
⎡1  -v - w⎤
⎢         ⎥
⎣0    1   ⎦

In [12]: 伽利略變換 * G
Out[12]: 
⎡1  -v - w⎤
⎢         ⎥
⎣0    1   ⎦

In [13]: 
</pre>
 

<span style="color: #003300;">貌似簡單了!!卻也讓人懷疑論述『座標系』之選取,為什麼僅止於『平移』的呢??</span>
<h1 id="firstHeading" class="firstHeading" lang="zh-TW"><span style="color: #003300;"><a style="color: #003300;" href="https://zh.wikipedia.org/zh-tw/%E5%B9%B3%E7%A7%BB">平移</a></span></h1>
<span style="color: #808080;">在<a class="mw-redirect" style="color: #808080;" title="仿射幾何" href="https://zh.wikipedia.org/wiki/%E4%BB%BF%E5%B0%84%E5%87%A0%E4%BD%95">仿射幾何</a>,<b>平移</b>(translation)是將物件的每<a class="mw-redirect" style="color: #808080;" title="點" href="https://zh.wikipedia.org/wiki/%E9%BB%9E">點</a>向同一方向移動相同距離。</span>

<span style="color: #808080;">它是<a class="mw-redirect" style="color: #808080;" title="等距同構" href="https://zh.wikipedia.org/wiki/%E7%AD%89%E8%B7%9D%E5%90%8C%E6%A7%8B">等距同構</a>,是<a style="color: #808080;" title="仿射空間" href="https://zh.wikipedia.org/wiki/%E4%BB%BF%E5%B0%84%E7%A9%BA%E9%97%B4">仿射空間</a>中<a style="color: #808080;" title="仿射變換" href="https://zh.wikipedia.org/wiki/%E4%BB%BF%E5%B0%84%E5%8F%98%E6%8D%A2">仿射變換</a>的一種。它可以視為將同一個<a style="color: #808080;" title="向量" href="https://zh.wikipedia.org/wiki/%E5%90%91%E9%87%8F">向量</a>加到每點上,或將坐標系統的中心移動所得的結果。即是說,若<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/35c1866e359fbfd2e0f606c725ba5cc37a5195d6" alt="\mathbf {v} " />是一個已知的向量,<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/dd73e3862cb92b016721b8c492eadb4e8a577527" alt="\mathbf{p}" />是空間中一點,平移 <img class="mwe-math-fallback-image-inline" src="https://wikimedia.org/api/rest_v1/media/math/render/svg/d2ef190970526b4786ba110e009049bb934d3015" alt="T_{{{\mathbf {v}}}}({\mathbf {p}})={\mathbf {p}}+{\mathbf {v}}" />。</span>

<span style="color: #808080;">將同一點平移兩次,結果可用一次平移表示,即 <img class="mwe-math-fallback-image-inline" src="https://wikimedia.org/api/rest_v1/media/math/render/svg/53b693a74c20fc4905434fc29332de3d33ab61ff" alt="T_{{{\mathbf {v}}}}(T_{{{\mathbf {u}}}}({\mathbf {p}}))=T_{{{\mathbf {v}}+{\mathbf {u}}}}({\mathbf {p}})" />,因此所有平移的集是一個<a style="color: #808080;" title="群" href="https://zh.wikipedia.org/wiki/%E7%BE%A4">群</a>,稱為<b>平移群</b>。這個群和空間同構,又是<a class="new" style="color: #808080;" title="歐幾里德群(頁面不存在)" href="https://zh.wikipedia.org/w/index.php?title=%E6%AD%90%E5%B9%BE%E9%87%8C%E5%BE%B7%E7%BE%A4&action=edit&redlink=1">歐幾里德群</a>E(n)的<a style="color: #808080;" title="正規子群" href="https://zh.wikipedia.org/wiki/%E6%AD%A3%E8%A7%84%E5%AD%90%E7%BE%A4">正規子群</a>。</span>

<span style="color: #808080;">T對E的<a style="color: #808080;" title="商群" href="https://zh.wikipedia.org/wiki/%E5%95%86%E7%BE%A4">商群</a>與<a style="color: #808080;" title="正交群" href="https://zh.wikipedia.org/wiki/%E6%AD%A3%E4%BA%A4%E7%BE%A4">正交群</a>O(n)同構:E(n) / T = O(n)。</span>

<img class="alignnone size-full wp-image-56644" src="http://www.freesandal.org/wp-content/uploads/220px-TraslazioneOK.png" alt="220px-TraslazioneOK" width="220" height="197" />

<span style="color: #808080;">平移將物件的每一點向同一方向移動相同距離。</span>

<span style="color: #808080;">………</span>

 

<span style="color: #003300;">難到『觀察者』之間的『座標系』不能『旋轉』的耶!!或許原因在於物理學比較專注於『相對性』原理。若是同時考慮『時間』之『平移』與『空間』之『旋轉』,恐怕難以簡明『表達』重要概念也??!!</span>
<h1 id="firstHeading" class="firstHeading" lang="zh-TW"><span style="color: #003300;"><a style="color: #003300;" href="https://zh.wikipedia.org/zh-tw/%E5%8F%98%E6%8D%A2%E7%9F%A9%E9%98%B5">變換矩陣</a></span></h1>
<span style="color: #808080;"><b>變換矩陣</b>是<a style="color: #808080;" title="數學" href="https://zh.wikipedia.org/wiki/%E6%95%B0%E5%AD%A6">數學</a><a style="color: #808080;" title="線性代數" href="https://zh.wikipedia.org/wiki/%E7%BA%BF%E6%80%A7%E4%BB%A3%E6%95%B0">線性代數</a>中的一個概念。</span>

<span style="color: #808080;">在<a style="color: #808080;" title="線性代數" href="https://zh.wikipedia.org/wiki/%E7%BA%BF%E6%80%A7%E4%BB%A3%E6%95%B0">線性代數</a>中,<a class="mw-redirect" style="color: #808080;" title="線性變換" href="https://zh.wikipedia.org/wiki/%E7%BA%BF%E6%80%A7%E5%8F%98%E6%8D%A2">線性變換</a>能夠用<a style="color: #808080;" title="矩陣" href="https://zh.wikipedia.org/wiki/%E7%9F%A9%E9%98%B5">矩陣</a>表示。如果<i>T</i>是一個把<b>R</b><sup><i>n</i></sup>映射到<b>R</b><sup><i>m</i></sup>的線性變換,且<i>x</i>是一個具有<i>n</i>個元素的<a style="color: #808080;" title="行向量" href="https://zh.wikipedia.org/wiki/%E8%A1%8C%E5%90%91%E9%87%8F">行向量</a>,那麼</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/ea38c119a0e701d009f7fc67b29f4064830d61b0" alt="T({\vec x})={\mathbf {A}}{\vec x}" /></span></dd></dl><span style="color: #808080;">我們把<i>m</i>×<i>n</i>的矩陣<b>A</b>,稱為<b><i>T</i>的變換矩陣</b>。</span>

<span style="color: #808080;">……</span>
<h2><span id=".E5.9C.A8.E4.BA.8C.E7.BB.B4.E5.9B.BE.E5.BD.A2.E4.B8.AD.E7.9A.84.E5.BA.94.E7.94.A8.E7.A4.BA.E4.BE.8B" class="mw-headline" style="color: #808080;">在二維圖形中的應用示例</span></h2>
<span style="color: #808080;">最為常用的幾何變換都是線性變換,這包括旋轉、縮放、切變、反射以及正投影。在二維空間中,線性變換可以用2×2的變換矩陣表示。</span>
<h3><span id=".E6.97.8B.E8.BD.AC" class="mw-headline" style="color: #ff9900;">旋轉</span></h3>
<span style="color: #808080;">繞原點逆時針<a style="color: #808080;" title="旋轉" href="https://zh.wikipedia.org/wiki/%E6%97%8B%E8%BD%AC">旋轉</a>θ度角的變換公式是 <img class="mwe-math-fallback-image-inline" src="https://wikimedia.org/api/rest_v1/media/math/render/svg/ea2a2afb8c2c5d404999fe1d9be93838cba5dc4c" alt="x'=x\cos \theta -y\sin \theta " />與 <img class="mwe-math-fallback-image-inline" src="https://wikimedia.org/api/rest_v1/media/math/render/svg/76867df645419a8c64b041271ed4b4cfb968cd09" alt="y'=x\sin \theta +y\cos \theta " />,用矩陣表示為:</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/8bcb27df8481ac7603f4f914ad707c9ee1be7393" alt="{\begin{pmatrix}x'\\y'\end{pmatrix}}={\begin{pmatrix}\cos \theta &-\sin \theta \\\sin \theta &\ cos\theta \end{pmatrix}}{\begin{pmatrix}x\\y\end{pmatrix}}" /></span></dd></dl>
<h3><span id=".E7.BC.A9.E6.94.BE" class="mw-headline" style="color: #ff9900;">縮放</span></h3>
<span style="color: #808080;"><a style="color: #808080;" title="縮放" href="https://zh.wikipedia.org/wiki/%E7%BC%A9%E6%94%BE">縮放</a>(反矩陣)公式為 <img class="mwe-math-fallback-image-inline" src="https://wikimedia.org/api/rest_v1/media/math/render/svg/96c5df9ada8e915668be98d23166db655aae37d1" alt="x'=s_{x}\cdot x" />與<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/39654008a50b6a5670519b77a7534bcff57dea88" alt="y'=s_{y}\cdot y" />,用矩陣表示為:</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/59986dd440056bdb15436fadfa7cba331970c3b5" alt="{\begin{pmatrix}x'\\y'\end{pmatrix}}={\begin{pmatrix}s_{x}&0\\0&s_{y}\end{pmatrix}}{\begin{pmatrix}x\\y\end{pmatrix}}" /></span></dd></dl>
<h3><span id=".E5.88.87.E5.8F.98" class="mw-headline" style="color: #ff9900;">切變</span></h3>
<span style="color: #808080;"><a class="mw-redirect" style="color: #808080;" title="切變" href="https://zh.wikipedia.org/wiki/%E5%88%87%E5%8F%98">切變</a>有兩種可能的形式,平行於<i>x</i>軸的切變為 <img class="mwe-math-fallback-image-inline" src="https://wikimedia.org/api/rest_v1/media/math/render/svg/4e6308dc0c636bf11db1c7a9eb205fe7643c23fd" alt="x'=x+ky" />與<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/e6239f12a70a7f715303934acf9dbae208fceb80" alt="y'=y" />,矩陣表示為:</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/f624067705d7c2fd3fe7617b7cfefe8fdbb8fed6" alt="{\begin{pmatrix}x'\\y'\end{pmatrix}}={\begin{pmatrix}1&k\\0&1\end{pmatrix}}{\begin{pmatrix}x\\y\end{pmatrix}}" /></span></dd></dl><span style="color: #808080;">平行於<i>y</i>軸的切變為<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/62cc09be3190c7464511712d6a1ba96481f83fa2" alt="x'=x" />與 <img class="mwe-math-fallback-image-inline" src="https://wikimedia.org/api/rest_v1/media/math/render/svg/fe73a538387223e1fc7b740f25df55eaaff2b080" alt="y'=y+kx" />,矩陣表示為:</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/900b7271f454574d08bcde375fc9332b702a10d0" alt="{\begin{pmatrix}x'\\y'\end{pmatrix}}={\begin{pmatrix}1&0\\k&1\end{pmatrix}}{\begin{pmatrix}x\\y\end{pmatrix}}" /></span></dd></dl>
<h3><span id=".E5.8F.8D.E5.B0.84" class="mw-headline" style="color: #ff9900;">反射</span></h3>
<span style="color: #808080;">為了沿經過原點的直線反射向量,假設(<i>u<sub>x</sub></i>, <i>u<sub>y</sub></i>)為直線方向的<a style="color: #808080;" title="單位向量" href="https://zh.wikipedia.org/wiki/%E5%8D%95%E4%BD%8D%E5%90%91%E9%87%8F">單位向量</a>。變換矩陣為:</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/2b68732b304cddf27e113ac8d5d4bbdfcad6bdc4" alt="{\begin{pmatrix}x'\\y'\end{pmatrix}}={\begin{pmatrix}2u_{x}^{2}-1&2u_{x}u_{y}\\2u_{x}u_{y}&2u_{y}^{2}-1\end{pmatrix}}{\begin{pmatrix}x\\y\end{pmatrix}}" /></span></dd></dl><span style="color: #808080;">不經過原點的直線的反射是仿射變換,而不是線性變換。</span>
<h3><span id=".E6.AD.A3.E6.8A.95.E5.BD.B1" class="mw-headline" style="color: #ff9900;">正投影</span></h3>
<span style="color: #808080;">為了將向量正投影到一條經過原點的直線,假設(<i>u<sub>x</sub></i>, <i>u<sub>y</sub></i>)是直線方向的<a style="color: #808080;" title="單位向量" href="https://zh.wikipedia.org/wiki/%E5%8D%95%E4%BD%8D%E5%90%91%E9%87%8F">單位向量</a>,變換矩陣為:</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/d9b12205261ce87af35f4f47843116cb4496bfeb" alt="{\begin{pmatrix}x'\\y'\end{pmatrix}}={\begin{pmatrix}u_{x}^{2}&u_{x}u_{y}\\u_{x}u_{y}&u_{y}^{2}\end{pmatrix}}{\begin{pmatrix}x\\y\end{pmatrix}}" /></span></dd></dl><span style="color: #808080;">同反射一樣,正投影到一條不經過原點的直線的變換是仿射變換,而不是線性變換。</span>

<span style="color: #808080;"><a class="new" style="color: #808080;" title="平行投影(頁面不存在)" href="https://zh.wikipedia.org/w/index.php?title=%E5%B9%B3%E8%A1%8C%E6%8A%95%E5%BD%B1&action=edit&redlink=1">平行投影</a>也是線性變換,也可以用矩陣表示。但是<a style="color: #808080;" title="透視投影" href="https://zh.wikipedia.org/wiki/%E9%80%8F%E8%A7%86%E6%8A%95%E5%BD%B1">透視投影</a>不是線性變換,必須用齊次坐標表示。</span>

<span style="color: #808080;">───</span>

 

<span style="color: #003300;">從『變換矩陣』看『旋轉』,總是有『零點』

*** Error message:
Missing $ inserted.
Missing $ inserted.
leading text: In [2]: init_
Missing $ inserted.
Unicode character α (U+03B1)
leading text: In [3]: xα
Unicode character β (U+03B2)
leading text: In [3]: xα, xβ
Unicode character γ (U+03B3)
leading text: In [3]: xα, xβ, xγ
Unicode character α (U+03B1)
leading text: In [3]: xα, xβ, xγ, yα
Unicode character β (U+03B2)
leading text: In [3]: xα, xβ, xγ, yα, yβ
Unicode character γ (U+03B3)
leading text: In [3]: xα, xβ, xγ, yα, yβ, yγ
Unicode character α (U+03B1)
leading text: ..., xγ, yα, yβ, yγ, v, w = symbols('xα
Unicode character β (U+03B2)
leading text: ..., yα, yβ, yγ, v, w = symbols('xα, xβ
Unicode character γ (U+03B3)
leading text: ..., yβ, yγ, v, w = symbols('xα, xβ, xγ

T \cdot \vec{0} = \vec{0}的,如是2 x 2$ 之矩陣豈足以兼顧『平移』和『旋轉』乎 !!??終究還是得進入『仿射空間』的矣︰

仿射空間,又稱線性流形,是數學中的幾何結構,這種結構是歐式空間仿射特性的推廣。在仿射空間中,點與點之間做差可以得到向量,點與向量做加法將得到另一個點,但是點與點之間不可以做加法。

非正式描述

下面的非正式描述可能比正式的定義容易理解一些:仿射空間是沒有起點只有方向大小的向量所構成的向量空間。假設有甲乙兩人,其中甲知道一個空間中真正的原點,但是乙認為另一個點p才是原點。現在求兩個向量ab的和。乙畫出papb的箭頭,然後用平行四邊形找到他認為的向量a + b。但是甲認為乙畫出的是向量p +(ap) +(bp)。同樣的,甲和乙可以計算向量ab線性組合,通常情況下他們會得到不同的結果。然而,請注意:

如果線性組合係數的和為1,那麼甲和乙將得到同樣的結果!

仿射空間就是這樣產生的:甲知道空間的「線性結構」。但是甲和乙都知道空間的「仿射結構」,即他們都知道空間中仿射組合的值,其中仿射組合的定義為係數和為1的線性組合。

如果乙:λa + (1 − λ)b 則甲為:p + λ(a − p) + (1 − λ)(b − p) = λa + (1 − λ)b.

那麼對於所有滿足λ + (1 − λ) = 1的係數,即使從不同的原點開始,甲乙將以同樣的線性組合描述同樣的點

具有仿射結構的集合就是一個仿射空間。

───

仿射變換

仿射變換,又稱仿射映射,是指在幾何中,一個向量空間進行一次線性變換並接上一個平移,變換為另一個向量空間。

一個對向量  {\vec {x}}平移 {\vec {b}},與旋轉放大縮小 A {\displaystyle A}  A的仿射映射為

{\vec {y}}=A{\vec {x}}+{\vec {b}}

上式在齊次座標上,等價於下面的式子

{\begin{bmatrix}{\vec {y}}\\1\end{bmatrix}}={\begin{bmatrix}A&{\vec {b}}\ \\0,\ldots ,0&1\end{bmatrix}}{\begin{bmatrix}{\vec {x}}\\1\end{bmatrix}}

碎形的研究裡,收縮平移仿射映射可以製造製具有自相似性碎形

200px-Fractal_fern_explained

一個使用仿射變換所製造有自相似性的碎形

……

表示

如上所示,仿射變換為兩函數的複合平移線性映射。普通向量代數用矩陣乘法呈現線性映射, 用向量加法表示平移。正式言之,於有限維度之例中,假如該線性映射被表示為一矩陣「A」,平移被表示為向量  \vec{b},一仿射映射 f可被表示為

{\vec {y}}=f({\vec {x}})=A{\vec {x}}+{\vec {b}}.

增廣矩陣

使用一 增廣矩陣 與一增廣向量, 用一矩陣乘法同時表示平移與線性映射是有可能的。此技術需要所有向量在其末端擴長 「1」且所有矩陣都於底部添加一排零,右邊擴長一列轉換向量,及右下角添加一個 「1」。

{\displaystyle {\begin{bmatrix}{\vec {y}}\\1\end{bmatrix}}=\left[{\begin{array}{ccc|c}\,&A&&{\vec {b}}\ \\0&\ldots &0&1\end{array}}\right]{\begin{bmatrix}{\vec {x}}\\1\end{bmatrix}}}

等價於y → = A x → + b → . {\displaystyle {\vec {y}}=A{\vec {x}}+{\vec {b}}.} {\vec {y}}=A{\vec {x}}+{\vec {b}}.

以上所言之擴長矩陣被稱為 「仿射變換矩陣」,又或稱為 「投射變換矩陣」 (其可應用於 投影轉換).

此表示法以 Kn半直積 與 GL(n, k)展示了 所有可逆 仿射變換的集合。 此為一個於眾函數集結下進行的一個 , 被稱為 仿射群

普通矩陣向量乘法總將原點映射至原點,因此無法呈現平移(原點必須映射至其他點)。藉由於所有向量上擴增一座標 「1」,我們將原空間映至更高維空間的一個子集合以進行變換。在該空間中,原本之空間佔有了擴長座標一的1的子集合。 因此原空間的原點可在(0,0, ... 0, 1). 原空間的平移可藉由更高維度空間的線性轉換來達成(即為錯切變換)。在高維度中的座標即為 齊次座標的一例。 假如原空間為歐幾里德, 則更高維空間為實射影空間.

使用齊次座標的優點為,藉由相對應矩陣之乘積,可將任意數目的仿射變換結合為一。此性質被大量運用於 計算機圖形, 計算機視覺機器人學

 

二維平面上的仿射變換可呈現於三維空間中。平移即為沿著z軸的錯切,旋轉則以z軸為軸心

 

 

 

 

 

 

 

 

 

 

 

光的世界︰派生科學計算五

《花非花》白居易

花非花,霧非霧,
夜半來,天明去,
來如春夢無多時,
去似朝雲無覓處。

 

香山居士這首詩別出心裁,令人想入非非。莫非

美人花,花非花,似花花解語。
彩雲霧,霧非霧,比霧霧生霞。
春夢恐醒,韶光將逝,如電亦如霧。
朝雲易散,彩霞難留,來去無覓處。

 

。引人『悟』悟吾心乎??感嘆人生幾何耶!!

幾人曾賞霧中花?
飄香方知花是花!
春夢朝雲花中霧!
何時才曉霧是霧?

 

暑中偶偶風雨突至,雷電交加,正是讚嘆自然現象之際,恰合說此萬花尺之時︰

萬花筒非筒?萬花尺非尺!
那位乘天光!千度百回!!
這位伴銀河!百媚千嬌!!
莫要問︰乾坤尺筒何時有??
無須答︰天地筒尺幾曾無!!

 

一八八零年代波蘭數學家 Bruno Abakanowicz 發明了『螺旋圖』Spirograph 。一九六四年英國工程師德尼斯‧費舍爾 Denys Fisher 發現使用多種『大小比值』不同的兩個內外『圓形齒輪』,當『內小圓形齒輪』上不同的『筆洞位置』在『外大圓形齒輪』上『循著圓周』轉動時,可以畫出各種美麗的『內旋輪線』 hypotrochoid 以及『外旋輪線 』epitrochoid。在經過一番齒輪『大小比值』與筆洞『位置比值』的研究後,費舍爾於隔年一九六五年的德國 Nuremberg 國際玩具展將之發表上市。由於它所繪出的『圖案』令人聯想到『萬花筒』 ,所以被我們叫做『萬花尺』。這是一個曾經『流行』過的『益智玩具』,其實它是了解『周期運動』組合的『複雜性』很好的『工具』。萬花尺內旋輪線的參數方程式可以表示為

\begin{array}{rcl} x(t)&=&R\left[(1-k)\cos t+lk\cos \frac{1-k}{k}t\right] ,\\[4pt] y(t)&=&R\left[(1-k)\sin t-lk\sin \frac{1-k}{k}t\right] .\\\end{array}

此處 R 是『外大齒輪』的半徑,k=\frac{r}{R} 是大小齒輪的『半徑比0\le k \le 1l=\frac{\rho}{r} 是筆洞所在位置到『內小齒輪』圓心的距離與『內小齒輪』半徑的比值 0\le l \le 1

網路上有一個『Spirograph Art』的網頁,假使讀者有興趣的話,不妨前去看看。

HypotrochoidOutThreeFifths

220px-Ellipse_as_hypotrochoid

200px-Spirograph

120px-Hypotrochoid2_2

120px-Epitrochoid_3

─── 摘自《萬花尺 Spirograph Art

 

自己圖繪數理之境,欣賞科學之美也!!??

雖說 IPython 的筆記本很好用,只因擷圖麻煩,字小恐或難讀,

 

利薩茹圖形

 

因此不易展示程式碼,故而每每以 Shell 為範。由於操作上大同小異﹐尚祈無礙矣。

 

【參考資料】

Plotting Module

Introduction

The plotting module allows you to make 2-dimensional and 3-dimensional plots. Presently the plots are rendered using matplotlib as a backend. It is also possible to plot 2-dimensional plots using a TextBackend if you don’t have matplotlib.

The plotting module has the following functions:

  • plot: Plots 2D line plots.
  • plot_parametric: Plots 2D parametric plots.
  • plot_implicit: Plots 2D implicit and region plots.
  • plot3d: Plots 3D plots of functions in two variables.
  • plot3d_parametric_line: Plots 3D line plots, defined by a parameter.
  • plot3d_parametric_surface: Plots 3D parametric surface plots.

The above functions are only for convenience and ease of use. It is possible to plot any plot by passing the corresponding Series class to Plot as argument.

 

【簡單範例】

pi@raspberrypi:~ $ ipython3
Python 3.4.2 (default, Oct 19 2014, 13:31:11) 
Type "copyright", "credits" or "license" for more information.

IPython 2.3.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: from sympy import *

In [2]: init_printing()

In [3]: R, r, ρ, t = symbols('R, r, ρ, t')

In [4]: x = R * ( (1 - r/R) * cos(t) + ρ/R * cos((R - r)/r * t) ) 

In [5]: y = R * ( (1 - r/R) * sin(t) - ρ/R * sin((R - r)/r * t) )

In [6]: x
Out[6]: 
  ⎛                      ⎛t⋅(R - r)⎞⎞
  ⎜                 ρ⋅cos⎜─────────⎟⎟
  ⎜⎛    r⎞               ⎝    r    ⎠⎟
R⋅⎜⎜1 - ─⎟⋅cos(t) + ────────────────⎟
  ⎝⎝    R⎠                 R        ⎠

In [7]: y
Out[7]: 
  ⎛                      ⎛t⋅(R - r)⎞⎞
  ⎜                 ρ⋅sin⎜─────────⎟⎟
  ⎜⎛    r⎞               ⎝    r    ⎠⎟
R⋅⎜⎜1 - ─⎟⋅sin(t) - ────────────────⎟
  ⎝⎝    R⎠                 R        ⎠

In [8]: x1 = x.subs([(R, 5), (r, 3), (ρ, 2)])

In [9]: y1 = y.subs([(R, 5), (r, 3), (ρ, 2)])

In [10]: x1
Out[10]: 
     ⎛2⋅t⎞           
2⋅cos⎜───⎟ + 2⋅cos(t)
     ⎝ 3 ⎠           

In [11]: y1
Out[11]: 
       ⎛2⋅t⎞           
- 2⋅sin⎜───⎟ + 2⋅sin(t)
       ⎝ 3 ⎠           

# Fig 1, Fig 2, Fig 3
In [12]: plotting.plot_parametric(x1, y1, (t, -5, 5))
Out[12]: <sympy.plotting.plot.Plot at 0x74b8cb10>

In [13]: plotting.plot_parametric(x1, y1, (t, -10, 10))
Out[13]: <sympy.plotting.plot.Plot at 0x72959d30>

In [14]: plotting.plot_parametric(x1, y1, (t, -100, 100))
Out[14]: <sympy.plotting.plot.Plot at 0x713cf990>

In [15]: 

 

【Fig 1, Fig 2, Fig 3】

五芒星_1

 

五芒星_2

 

五芒星_3

 

 

 

 

 

 

 

 

 

 

 

 

光的世界︰派生科學計算四

詩經‧國風‧豳風‧伐柯

伐柯如何?匪斧不克。

取妻如何?匪媒不得。

伐柯伐柯,其則不遠。

我覯之子,籩豆有踐。

 

伐『柯』柯即是製作斧柄,卻是非斧不行??將之比作娶『妻』

※《説文解字》: 柯,斧柄也。从木,可聲。

實在費疑猜??若思善用『工具』能夠創造更好的『工具』,那麼『伐柯伐柯,其則不遠。』果真『有理有則』的乎!?因此假借 SymPy 『符號矩陣』學習『矩陣』,也是『順理而行』的了?!

這裡僅以『基本矩陣』之法,求解一般 2x2 矩陣之『反矩陣』M 為例,演義這則『伐柯取妻』有趣之事︰

if

E \cdot M = (E_n \cdot \cdots E_2 \cdot E_1)  \cdot M = I

then

E = M^{-1}

M = {E_1}^{-1} \cdot {E_2}^{-1} \cdot \cdots {E_n}^{-1} = E^{-1}

 

望可消消暑氣也!!??

pi@raspberrypi:~ $ ipython3
Python 3.4.2 (default, Oct 19 2014, 13:31:11) 
Type "copyright", "credits" or "license" for more information.

IPython 2.3.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: from sympy import *

In [2]: init_printing()

In [3]: a11, a12, a21,a22 = symbols('a11, a12, a21,a22')

# 一般 2x2 矩陣 M
⎡a₁₁ a₁₂⎤
⎢       ⎥
⎣a₂₁ a₂₂⎦
In [4]: M = Matrix([[a11, a12], [a21,a22]])

# 試以『基本矩陣』求解其『反矩陣』
# 消去 a21
In [5]: E1 = Matrix([[1, 0], [-a21, a11]])

In [6]: E1
Out[6]: 
⎡ 1     0 ⎤
⎢         ⎥
⎣-a₂₁  a₁₁⎦

In [7]: E1 * M
Out[7]: 
⎡a₁₁         a₁₂       ⎤
⎢                      ⎥
⎣ 0   a₁₁⋅a₂₂ - a₁₂⋅a₂₁⎦

# 消去 a12
In [8]: E2 = Matrix([[a11*a22 - a12*a21, -a12], [0, 1]])

In [9]: E2
Out[9]: 
⎡a₁₁⋅a₂₂ - a₁₂⋅a₂₁  -a₁₂⎤
⎢                       ⎥
⎣        0           1  ⎦

In [10]: E2 * E1 * M
Out[10]: 
⎡   2                                     ⎤
⎢a₁₁ ⋅a₂₂ - a₁₁⋅a₁₂⋅a₂₁          0        ⎥
⎢                                         ⎥
⎣          0             a₁₁⋅a₂₂ - a₁₂⋅a₂₁⎦

# 歸一化
In [11]: E3 = Matrix([[1/(a11*(a11*a22 - a12*a21)), 0], [0, 1/(a11*a22 - a12*a21)]])

In [12]: E3
Out[12]: 
⎡           1                              ⎤
⎢───────────────────────          0        ⎥
⎢a₁₁⋅(a₁₁⋅a₂₂ - a₁₂⋅a₂₁)                   ⎥
⎢                                          ⎥
⎢                                 1        ⎥
⎢           0             ─────────────────⎥
⎣                         a₁₁⋅a₂₂ - a₁₂⋅a₂₁⎦

In [13]: E3 * E2 * E1 * M
Out[13]: 
⎡    ⎛        a₁₂⋅a₂₁            1 ⎞        a₁₂⋅a₂₁              a₁₂⋅a₂₂      
⎢a₁₁⋅⎜─────────────────────── + ───⎟ - ─────────────────  - ───────────────── 
⎢    ⎝a₁₁⋅(a₁₁⋅a₂₂ - a₁₂⋅a₂₁)   a₁₁⎠   a₁₁⋅a₂₂ - a₁₂⋅a₂₁    a₁₁⋅a₂₂ - a₁₂⋅a₂₁ 
⎢                                                                             
⎢                                                                        a₁₁⋅a
⎢                           0                                       ──────────
⎣                                                                   a₁₁⋅a₂₂ - 

      ⎛        a₁₂⋅a₂₁            1 ⎞⎤
+ a₁₂⋅⎜─────────────────────── + ───⎟⎥
      ⎝a₁₁⋅(a₁₁⋅a₂₂ - a₁₂⋅a₂₁)   a₁₁⎠⎥
                                     ⎥
₂₂             a₁₂⋅a₂₁               ⎥
─────── - ─────────────────          ⎥
a₁₂⋅a₂₁   a₁₁⋅a₂₂ - a₁₂⋅a₂₁          ⎦

# 驗證化作『單位矩陣』
In [14]: (E3 * E2 * E1 * M)[0,0]
Out[14]: 
    ⎛        a₁₂⋅a₂₁            1 ⎞        a₁₂⋅a₂₁     
a₁₁⋅⎜─────────────────────── + ───⎟ - ─────────────────
    ⎝a₁₁⋅(a₁₁⋅a₂₂ - a₁₂⋅a₂₁)   a₁₁⎠   a₁₁⋅a₂₂ - a₁₂⋅a₂₁

In [15]: (E3 * E2 * E1 * M)[0,0].simplify()
Out[15]: 1

In [16]: (E3 * E2 * E1 * M)[1,1]
Out[16]: 
     a₁₁⋅a₂₂             a₁₂⋅a₂₁     
───────────────── - ─────────────────
a₁₁⋅a₂₂ - a₁₂⋅a₂₁   a₁₁⋅a₂₂ - a₁₂⋅a₂₁

In [17]: (E3 * E2 * E1 * M)[1,1].simplify()
Out[17]: 1

# 簡化『反矩陣』
In [18]: E3 * E2 * E1
Out[18]: 
⎡        a₁₂⋅a₂₁            1         -a₁₂       ⎤
⎢─────────────────────── + ───  ─────────────────⎥
⎢a₁₁⋅(a₁₁⋅a₂₂ - a₁₂⋅a₂₁)   a₁₁  a₁₁⋅a₂₂ - a₁₂⋅a₂₁⎥
⎢                                                ⎥
⎢            -a₂₁                      a₁₁       ⎥
⎢      ─────────────────        ─────────────────⎥
⎣      a₁₁⋅a₂₂ - a₁₂⋅a₂₁        a₁₁⋅a₂₂ - a₁₂⋅a₂₁⎦

In [19]: (E3 * E2 * E1)[0,0].simplify()
Out[19]: 
       a₂₂       
─────────────────
a₁₁⋅a₂₂ - a₁₂⋅a₂₁

In [20]: (E3 * E2 * E1)[0,1].simplify()
Out[20]: 
      -a₁₂       
─────────────────
a₁₁⋅a₂₂ - a₁₂⋅a₂₁

In [21]: (E3 * E2 * E1)[1,0].simplify()
Out[21]: 
      -a₂₁       
─────────────────
a₁₁⋅a₂₂ - a₁₂⋅a₂₁

In [22]: (E3 * E2 * E1)[1,1].simplify()
Out[22]: 
       a₁₁       
─────────────────
a₁₁⋅a₂₂ - a₁₂⋅a₂₁

In [23]: E = Matrix([[a22/(a11*a22 -a12*a21), -a12/(a11*a22 -a12*a21)], [-a21/(a11*a22 -a12*a21), a11/(a11*a22 -a12*a21)]])

In [24]: E
Out[24]: 
⎡       a₂₂               -a₁₂       ⎤
⎢─────────────────  ─────────────────⎥
⎢a₁₁⋅a₂₂ - a₁₂⋅a₂₁  a₁₁⋅a₂₂ - a₁₂⋅a₂₁⎥
⎢                                    ⎥
⎢      -a₂₁                a₁₁       ⎥
⎢─────────────────  ─────────────────⎥
⎣a₁₁⋅a₂₂ - a₁₂⋅a₂₁  a₁₁⋅a₂₂ - a₁₂⋅a₂₁⎦

In [25]: E * M
Out[25]: 
⎡     a₁₁⋅a₂₂             a₁₂⋅a₂₁                                            ⎤
⎢───────────────── - ─────────────────                    0                  ⎥
⎢a₁₁⋅a₂₂ - a₁₂⋅a₂₁   a₁₁⋅a₂₂ - a₁₂⋅a₂₁                                       ⎥
⎢                                                                            ⎥
⎢                                            a₁₁⋅a₂₂             a₁₂⋅a₂₁     ⎥
⎢                  0                    ───────────────── - ─────────────────⎥
⎣                                       a₁₁⋅a₂₂ - a₁₂⋅a₂₁   a₁₁⋅a₂₂ - a₁₂⋅a₂₁⎦

# 探索這些『基本矩陣』的性質
In [26]: E1
Out[26]: 
⎡ 1     0 ⎤
⎢         ⎥
⎣-a₂₁  a₁₁⎦

In [27]: E1.det()
Out[27]: a₁₁

In [28]: E1.inv()
Out[28]: 
⎡ 1    0 ⎤
⎢        ⎥
⎢a₂₁   1 ⎥
⎢───  ───⎥
⎣a₁₁  a₁₁⎦

In [29]: E2
Out[29]: 
⎡a₁₁⋅a₂₂ - a₁₂⋅a₂₁  -a₁₂⎤
⎢                       ⎥
⎣        0           1  ⎦

In [30]: E2.det()
Out[30]: a₁₁⋅a₂₂ - a₁₂⋅a₂₁

In [31]: E2.inv()
Out[31]: 
⎡        1                 a₁₂       ⎤
⎢─────────────────  ─────────────────⎥
⎢a₁₁⋅a₂₂ - a₁₂⋅a₂₁  a₁₁⋅a₂₂ - a₁₂⋅a₂₁⎥
⎢                                    ⎥
⎣        0                  1        ⎦

In [32]: E3
Out[32]: 
⎡           1                              ⎤
⎢───────────────────────          0        ⎥
⎢a₁₁⋅(a₁₁⋅a₂₂ - a₁₂⋅a₂₁)                   ⎥
⎢                                          ⎥
⎢                                 1        ⎥
⎢           0             ─────────────────⎥
⎣                         a₁₁⋅a₂₂ - a₁₂⋅a₂₁⎦

In [33]: E3.det()
Out[33]: 
                      1                       
──────────────────────────────────────────────
   3    2        2                      2    2
a₁₁ ⋅a₂₂  - 2⋅a₁₁ ⋅a₁₂⋅a₂₁⋅a₂₂ + a₁₁⋅a₁₂ ⋅a₂₁ 

In [34]: E3.det().simplify()
Out[34]: 
                       1                       
───────────────────────────────────────────────
    ⎛   2    2                          2    2⎞
a₁₁⋅⎝a₁₁ ⋅a₂₂  - 2⋅a₁₁⋅a₁₂⋅a₂₁⋅a₂₂ + a₁₂ ⋅a₂₁ ⎠

In [35]: E3.det().simplify().factor()
Out[35]: 
           1            
────────────────────────
                       2
a₁₁⋅(a₁₁⋅a₂₂ - a₁₂⋅a₂₁) 

In [36]: E3.inv()
Out[36]: 
⎡a₁₁⋅(a₁₁⋅a₂₂ - a₁₂⋅a₂₁)          0        ⎤
⎢                                          ⎥
⎣           0             a₁₁⋅a₂₂ - a₁₂⋅a₂₁⎦

In [37]: E1.det() * E2.det() * E3.det()
Out[37]: 
           a₁₁⋅(a₁₁⋅a₂₂ - a₁₂⋅a₂₁)            
──────────────────────────────────────────────
   3    2        2                      2    2
a₁₁ ⋅a₂₂  - 2⋅a₁₁ ⋅a₁₂⋅a₂₁⋅a₂₂ + a₁₁⋅a₁₂ ⋅a₂₁ 

In [38]: (E1.det() * E2.det() * E3.det()).simplify()
Out[38]: 
        1        
─────────────────
a₁₁⋅a₂₂ - a₁₂⋅a₂₁

# 確定 M 可用『基本矩陣』作表達
In [39]: E1.inv() * E2.inv() * E3.inv()
Out[39]: 
⎡a₁₁                          a₁₂                        ⎤
⎢                                                        ⎥
⎢                         ⎛        a₁₂⋅a₂₁            1 ⎞⎥
⎢a₂₁  (a₁₁⋅a₂₂ - a₁₂⋅a₂₁)⋅⎜─────────────────────── + ───⎟⎥
⎣                         ⎝a₁₁⋅(a₁₁⋅a₂₂ - a₁₂⋅a₂₁)   a₁₁⎠⎦

In [40]: (E1.inv() * E2.inv() * E3.inv())[1,1].simplify()
Out[40]: a₂₂