跳轉到內容

分形/計算機圖形技術/2D/變換

來自華夏公益教科書,自由的教科書,開放的世界

平面變換

  • 變換
  • 投影
    • 製圖地圖投影[1](在 3D 到 2D 圖形的情況下)[2]
  • 對映

2D 光柵圖形中的對映是一個複雜的函式 ,它將複平面對映到複平面。


它被實現為點變換。

它通常表示為


其中

  • 是複平面的一個點(輸入)
  • 是影像複平面的一個點(輸出 = 結果)

示例程式碼

[編輯 | 編輯原始碼]

例如,墨卡託:[3]


function Spherical_mercator(x, y) {
  return [x, Math.log(Math.tan(Math.PI / 4 + y / 2))];
}

function transverseMercatorRaw(lambda, phi) {
  return [log(tan((halfPi + phi) / 2)), -lambda];
}

transverseMercatorRaw.invert = function(x, y) {
  return [-y, 2 * atan(exp(x)) - halfPi];
};

如果有人使用離散幾何(多邊形和折線),那麼投影就很難實現。必須在精度和效能之間取得平衡。 [4]



// https://github.com/adammaj1/Mandelbrot-Sets-Alternate-Parameter-Planes/blob/main/src/lcm/d.c
// projection from p to c 
complex double map_parameter(const ParameterTypeT ParameterType, const complex double parameter){

	
	complex double p; 
	// plane transformation 
	switch(ParameterType){
	
		case c_identity :{p = parameter;  break;}
		
		case c_inverted :{p = 1.0/parameter; break;}
		
		case c_parabola :{p = 0.25+ 1.0/parameter; break;}
		
		case c_Myrberg_type :{p = cf - 1.0/parameter; break;}
		
		case c_inverted_2_type :{p = -2.0 + 1.0/parameter; break;}
		
		case c_exp :{p = cf + cexp(parameter) ; break;} // here one can change cf to get different image 
		
		
		case lambda_identity :{ p = parameter;  break;}
		
		case lambda_inverted_type :{p = 1.0/parameter; break;}
		
		case lambda_inverted_1_type :{p =1.0+ 1.0/parameter; break;}
		
		default: {p = parameter;}
	}

對映分類

  • 基於物件的對映(影像物件是具有相同整數值的連線畫素集)
  • 基於畫素的對映


2D 圖形中的變換(對映)

  • 基本型別
  • 複合變換[5]


矩陣的使用

  • 不使用矩陣(使用函式)
  • 使用矩陣

座標


  • "矩陣乘法不滿足交換律。變換的順序至關重要——旋轉後平移與平移後旋轉截然不同" [6]


實現




仿射變換

[編輯 | 編輯原始碼]

為了用矩陣表示仿射變換,我們可以使用齊次座標。這意味著將 2 向量 (x, y) 表示為 3 向量 (x, y, 1),更高維度也是如此。

2D 仿射變換矩陣



變換名稱 仿射矩陣 示例
恆等(變換到原始影像)
平移
反射
縮放
旋轉
其中 θ = π/6 =30°
剪下

仿射變換適用於將兩幅或多幅影像對齊(配準)的配準過程。一個影像配準的例子是全景影像的生成,全景影像是多幅拼接在一起的影像的產物。




縮放或調整大小

[編輯 | 編輯原始碼]

關於原點按比例因子縮放物體

 


變為


縮放

  • 均勻(在縮放時保持物體的比例):sx = sy
  • 非均勻:sx != sy


在保持固定中心點的情況下調整物體大小 = 關於其自身中心縮放物體

  • 寬度' = 寬度 * sx
  • 高度' = 高度 * sy
  • 計算中心點的角座標


複數平移是一個對映[7]

其中

使用這種系統,平移可以用矩陣乘法表示。 函式形式

 
 

變為

旋轉

[edit | edit source]

繞原點以角度 θ 逆時針(正方向)旋轉的函式形式為

 
.  

寫成矩陣形式,就變成了:[8]


類似地,繞原點順時針(負方向)旋轉的函式形式為

 
 

矩陣形式為


這些公式假設x軸指向右側,y軸指向上方。



歸一化座標下的逆時針旋轉矩陣



沒有矩陣的 C 程式碼

 
/* 

C program to rotate an object by a given angle about a given point
gcc r.c -Wall -Wextra -lm
./a.out
*/

#include <stdio.h>
#include <math.h> 
#include <complex.h> 		// complex numbers : https://stackoverflow.com/questions/6418807/how-to-work-with-complex-numbers-in-c


//The sin() function returns the value in the range of [-1, 1]

/*
https://stackoverflow.com/questions/2259476/rotating-a-point-about-another-point-2d 
First subtract the pivot point (cx,cy), then rotate it (counter clock-wise), then add the point again.
*/


 complex double rotate_point(const complex double center, const double angle_in_radians, const complex double point )
{
	// translate point to center
	complex double translated_point = creal(point) - creal(center)  + (cimag(point) - cimag(center))*I;

	// rotate point counter clock-wise by a given angle about a given pivot point ( center)
	double s = sin(angle_in_radians);
	double c = cos(angle_in_radians);
	complex double new_point = creal(translated_point) * c - cimag(translated_point) * s + (creal(translated_point) * s + cimag(translated_point) * c)*I;

	// translate point back
	new_point = creal(new_point) + creal(center) +(cimag(new_point) + cimag(center))*I;
  
  
	return new_point;
}

#define kMax 6

// center, angle_rad, point 
double examples[kMax][5] = {
		{50,-50, -0.7853982, 100,100 },
		{50,-50, -0.7853982, 100,200 },
		{50,-50, -0.7853982, 200,200 },
		{0,0, 1.570796, 100,100}, 
		{0,0, 1.570796, 150,200}, 
		{0,0, 1.570796, 200,200} 

};

int main(void){

	
	
	
	int k;
	
	
	
	complex double center ;
	double angle_r ; 
	complex double point ;
	complex double rotated_point;
	
	
	for (k=0; k<kMax; ++k){
		center = examples[k][0] + examples[k][1] * I ;
		angle_r = examples[k][2]; 
		point = examples[k][3] + examples[k][4] * I ;
		rotated_point = rotate_point(center, angle_r, point );
		fprintf(stdout, "point %f%+f*I rotated about %f%+f*I  by %f radians is %f%+f*I \n", creal(point), cimag(point), creal(center), cimag(center), angle_r, creal(rotated_point), cimag(rotated_point));
		}
	
	 


	return 0;
}

輸出

point 100.000000+100.000000*I rotated about 50.000000-50.000000*I  by -0.785398 radians is 191.421359+20.710673*I 
point 100.000000+200.000000*I rotated about 50.000000-50.000000*I  by -0.785398 radians is 262.132040+91.421348*I 
point 200.000000+200.000000*I rotated about 50.000000-50.000000*I  by -0.785398 radians is 332.842715+20.710668*I 
point 100.000000+100.000000*I rotated about 0.000000+0.000000*I  by 1.570796 radians is -99.999967+100.000033*I 
point 150.000000+200.000000*I rotated about 0.000000+0.000000*I  by 1.570796 radians is -199.999951+150.000065*I 
point 200.000000+200.000000*I rotated about 0.000000+0.000000*I  by 1.570796 radians is -199.999935+200.000065*I 

其他有趣的對映

[edit | edit source]


例子:[9][10]

共形對映

[edit | edit source]
  • "共形對映保持角度,並將無窮小圓對映到無窮小圓。 非共形對映將無窮小圓對映到無窮小橢圓(或更糟)。" Claude Heiland-Allen
  • "複函式 在無窮遠處是共形的,如果函式 在 0 處是共形的。 這等同於通常的關於共形的定義,即在大小和方向(順時針/逆時針)方面保持角度不變,如果你將 視為在黎曼球體的“北極”處保持角度不變。"[22]

共形對映

共形對映詞典,作者:John H. Mathews 和 Russell W. Howell(2008 年)

製圖地圖投影

[edit | edit source]

圓柱投影

[edit | edit source]
球體到圓柱的正切(赤道)投影的幾何形狀。

圓柱投影(或圓柱 p.)將球體(無極點)對映到圓柱上[23][24]

茹科夫斯基變換(對映)

[edit | edit source]

描述 

域著色或復相圖

[編輯 | 編輯原始碼]

複雜函式的視覺化

模形式

[編輯 | 編輯原始碼]

黎曼對映

[編輯 | 編輯原始碼]

參考文獻

[編輯 | 編輯原始碼]
  1. 維基百科中的地圖投影
  2. observable: plot-projections
  3. 維基百科中的橫軸墨卡託投影
  4. : JavaScript 中的地理投影、球形形狀和球面三角學
  5. geeksforgeeks : 2D 圖形中的複合變換
  6. Nicolas Holzschuch 博士的 2D 變換和齊次座標 開普敦大學
  7. Terr, David. "複雜平移." 來自 MathWorld--Wolfram Web 資源,由 Eric W. Weisstein 建立。
  8. http://ocw.mit.edu/courses/aeronautics-and-astronautics/16-07-dynamics-fall-2009/lecture-notes/MIT16_07F09_Lec03.pdf Template:Bare URL PDF
  9. opentextbc.ca: 地理資訊本質
  10. wolfram : ComplexFunctionsAppliedToASquare
  11. scikit-image.org 文件: swirl
  12. Alexandre Bernardino 的對數極座標對映
  13. Weisstein, Eric W. "拋物柱面座標." 來自 MathWorld--Wolfram Web 資源
  14. Weisstein, Eric W. "拋物線座標." 來自 MathWorld--Wolfram Web 資源。
  15. Bjørnar Steinnes Luteberget 的共形對映數值逼近
  16. processing : transform2d
  17. 看起來圓形的正方形: Saul Schleimer 和 Henry Segerman 的球面影像變換
  18. fractalforums inflection-mappings
  19. theinnerframe : playing-with-circular-images
  20. theinnerframe: squaring-the-circle
  21. fractalforums: fractal-on-sphere
  22. math.stackexchange 問題: conformal-mappings-of-riemann-sphere
  23. Paul Bourke 編寫的球面投影(立體投影和圓柱投影)
  24. Weisstein, Eric W. "圓柱投影." 來自 MathWorld--Wolfram Web 資源。
  25. johndcook : joukowsky-transformation
華夏公益教科書