[計算幾何]Matrices&Linear Systems:Tuples

Conceptually, a tuple is an ordered list of elements; however,
becausethis book is about geometry in computer graphics, we’re going
to restrict our discussions to real numbers.

概念上,tuple是有序的要素列表;在計算幾何中,減小討論範圍到實數部分。

  • 本書中的符號和僞代碼表示方法

本書中的符號和僞代碼表示方法

Nevertheless, it should be remembered that tuples and matrices may
(conceptually) be composed of complex numbers, or any arbitrary type,
and that much of what is discussed (in terms of properties, in
particular) applies to arbitrary element types.

數組和矩陣都可能由複數組成,亦或者是任意類型,大部分的在討論,任意類型的應用。

2.2.1 定義

Generically, we refer to a tuple of n elements as an n-tuple and use
subscript notation for it: a = (a 1 , a 2 , … , a n ).

n個元素,有各自的下標

舉例

a = (6, 5, 42)
b = (3.14, 3.75, 8, 15)

2.2.2 算法操作

相加(減)

Addition (and subtraction) of tuples is meaningful if each tuple has
the same number of elements and the elements represent “corresponding”
quantities.

對兩個有相同的元素數量,以及每個元素代表相同的元素數量的元組成對(pairwise)相加。

#Addtion
a = (6, 3, 7)
b = (1, 2, 4)

add =  tuple([a[i]+b[i] for i in range(len(a))])
print add
#(7, 5, 11)

相乘(除)

#Multiplication
scalars = 2.0
#2*(6, 3, 7) = (12,6,14)
#(6, 3, 7) /2 = (3, 1.5, 3.5)
mul = tuple([i*scalars for i in a])
div = tuple([i/scalars for i in a])
print mul
#(12.0, 6.0, 14.0)
print div
#(3.0, 1.5, 3.5)

複雜的數組操作會提及不同的數據類型,這裏先不展開,放到後面適當的語境中展開。

矩陣的representation, properties&application 會成爲後面章節的主題。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章