3D空間的直線能否只用四個變量來表達?

三個座標 x, y, z 可以確定3D空間的任意一點。

形如 x + y + z = 1, 的方程可以表示3d 空間的一個平面, 該平面與x, y, z軸的交點分別爲(1, 0, 0), (0, 1, 0), (0, 0, 1) 三個點,那麼推廣到一般情形, ax + by + cz = d, (a, b, c, d 爲四個變量),當a, b, c, d都給定時,可以唯一的確定3 D空間的任意一個平面,對於3d 空間的直線能否也只用四個變量,來唯一的確定這條直線呢?

對於3D中的直線來說,有幾種表示法,用了六個變量的兩點式,用3D直線上兩個點來確定該直線。
用了八個變量的兩平面相交的方式。
{(x,y,z)∈R3:a1x+b1y+c1z=d1 and a2x+b2y+c2z=d2}.

用六個變量的點斜式
Here are three ways to describe the formula of a line in 3 dimensions. Let’s assume the line L passes through the point (x0,y0,z0) and is traveling in the direction (a,b,c).

(x,y,z)=(x0,y0,z0)+t(a,b,c) (這裏的 t 不是變量)

https://math.stackexchange.com/questions/404440/what-is-the-equation-for-a-3d-line

還有用了六個變量的投影式
a X + b Y + c = 0 (3d直線從 z 軸投影的XY平面的一般式 2D 直線方程)
d X + e Z + f = 0 (3d直線從 y 軸投影的XZ平面的一般式 2D 直線方程)
https://blog.codingnow.com/2006/12/eioaeoeiessiecea.html

研究一下three.js的源代碼,在Plane.js 中發現其對平面的抽象,非常優美,非常好用,也是隻用了四個變量,就能唯一確定 3d 空間的任意平面,分別是平面的法向量normal, 和constantconstant表示該平面沿着法向量指定的方向位移多少距離,使得座標系原點(0,0,0)落在該平面上

/**
 * @author bhouston / http://clara.io
 */

function Plane( normal, constant ) {

	// normal is assumed to be normalized

	this.normal = ( normal !== undefined ) ? normal : new Vector3( 1, 0, 0 );
	this.constant = ( constant !== undefined ) ? constant : 0;

}

three.js 中對於3D 直線的抽象,不太令我滿意,使用的是兩點式,Line3.js

/**
 * @author bhouston / http://clara.io
 */

function Line3( start, end ) {

	this.start = ( start !== undefined ) ? start : new Vector3();
	this.end = ( end !== undefined ) ? end : new Vector3();

}

還有射線,Ray.js,使用的點斜式

/**
 * @author bhouston / http://clara.io
 */

function Ray( origin, direction ) {

	this.origin = ( origin !== undefined ) ? origin : new Vector3();
	this.direction = ( direction !== undefined ) ? direction : new Vector3();

}

射線沒啥好說的,用六個變量是合適的

用六個變量來表示3D線段也是很合適的,而用六個變量來表示3D直線是不是太多了,
可以這樣用五個變量來表示3D直線,設任意3D 直線L,
直線L可以唯一的確定一個平面 P,平面 P的法向量和L平行,而且平面 P正好過原點,這樣平面P就只用了三個變量(x,y,z)可以表示,(x,y,z)是平面 P的法向量,平面 P的constant 始終爲 0,這裏constant不算變量,直線L 和 平面 P的交點是個二維座標 (n, m), 這樣就用了五個變量(x, y, z, n, m)確定 任意3D 直線L

還能不能更少點?只用四個變量來確定 任意3D 直線,或者說用數學來證明根本不可能用四個變量來確定 任意3D 直線 ?

jscolor.js 源碼中的片段,
判斷字體顏色是否應該應用黑色背景

this.isLight = function () {
			return (
				0.213 * this.rgb[0] +
				0.715 * this.rgb[1] +
				0.072 * this.rgb[2] >
				255 / 2
			);
		};

rgb顏色明暗度變化的實現思路
先把rgb 轉換爲hsv (色度,飽和度,明暗度)顏色,調整hsv 中 v,最後把hsv 轉換爲rgb

// r: 0-255
		// g: 0-255
		// b: 0-255
		//
		// returns: [ 0-360, 0-100, 0-100 ]
		//
		function RGB_HSV (r, g, b) {
			r /= 255;
			g /= 255;
			b /= 255;
			var n = Math.min(Math.min(r,g),b);
			var v = Math.max(Math.max(r,g),b);
			var m = v - n;
			if (m === 0) { return [ null, 0, 100 * v ]; }
			var h = r===n ? 3+(b-g)/m : (g===n ? 5+(r-b)/m : 1+(g-r)/m);
			return [
				60 * (h===6?0:h),
				100 * (m/v),
				100 * v
			];
		}
		
// h: 0-360
		// s: 0-100
		// v: 0-100
		//
		// returns: [ 0-255, 0-255, 0-255 ]
		//
		function HSV_RGB (h, s, v) {
			var u = 255 * (v / 100);

			if (h === null) {
				return [ u, u, u ];
			}

			h /= 60;
			s /= 100;

			var i = Math.floor(h);
			var f = i%2 ? h-i : 1-(h-i);
			var m = u * (1 - s);
			var n = u * (1 - s * f);
			switch (i) {
				case 6:
				case 0: return [u,n,m];
				case 1: return [n,u,m];
				case 2: return [m,u,n];
				case 3: return [m,n,u];
				case 4: return [n,m,u];
				case 5: return [u,m,n];
			}
		}

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