書(shū)名:代碼本色:用編程模擬自然系統(tǒng)
作者:Daniel Shiffman
譯者:周晗彬
ISBN:978-7-115-36947-5
總目錄
第 1 章 向量
一、目錄
第 1 章 向量
- 1.1 向量
- 1.2 Processing中的向量
- 1.3 向量的加法
- 1.4 更多的向量運(yùn)算
1.4.1 向量的減法
1.4.2 向量加減法的運(yùn)算律
1.4.3 向量的乘法
1.4.4 更多的向量運(yùn)算律 - 1.5 向量的長(zhǎng)度
- 1.6 單位化向量
- 1.7 向量的運(yùn)動(dòng):速度
- 1.8 向量的運(yùn)動(dòng):加速度
運(yùn)動(dòng)101:速度和隨機(jī)加速度 - 1.9 靜態(tài)函數(shù)和非靜態(tài)函數(shù)
- 1.10 加速度的交互
一組同時(shí)朝著鼠標(biāo)加速的運(yùn)動(dòng)物體
1.1 向量
一党窜、向量定義
??向量(vector)拗引。本書(shū)中出現(xiàn)的“向量”均指歐幾里得向量。
??歐幾里得向量(Euclidean vector幌衣,以希臘數(shù)學(xué)家歐幾里得的名字命名矾削,也稱(chēng)作幾何向量)壤玫,它的定義是:
??一個(gè)既有大小又有方向的幾何對(duì)象。
??向量通常被繪制為一個(gè)帶箭頭的線段哼凯,線段的長(zhǎng)度代表向量的大小欲间,箭頭所指的方向就是向量的方向。
二断部、沒(méi)有使用向量的彈球程序
float x = 100;
float y = 100;
float xspeed = 2.5;
float yspeed = 2;
void setup() {
size(300, 200);
smooth();
}
void draw() {
background(255);
// Add the current speed to the position.
x = x + xspeed;
y = y + yspeed;
if ((x > width) || (x < 0)) {
xspeed = xspeed * -1;
}
if ((y > height) || (y < 0)) {
yspeed = yspeed * -1;
}
// Display circle at x position
stroke(0);
strokeWeight(2);
fill(127);
ellipse(x, y, 48, 48);
}
彈球程序
三猎贴、使用向量
??對(duì)于下面這些變量:
float x;
float y;
float xspeed;
float yspeed;
??可以把它們替換成:
Vector location;
Vector speed;