<a target="_blank" href="http://blog.csdn.net/omni360">轉載請保留此句:商域無疆 - 本部落格專注于 靈活開發及移動和物聯裝置研究:資料可視化、GOLANG、Html5、WEBGL、THREE.JS,否則。出自本部落格的文章拒絕轉載或再轉載,謝謝合作。</a>
俺也是剛開始學,好多地兒肯定不正确還請見諒.
下面代碼是THREE.JS 源代碼檔案裡Math/Sphere.js檔案的凝視.
radius : 0; //指派或者初始化radius
};
/****************************************
****以下是Sphere對象提供的功能函數.
****************************************/
THREE.Sphere.prototype = {
constructor: THREE.Sphere, //構造器,傳回對建立此對象的Sphere函數的引用
/*
///set方法用來從新設定球體的起始點,結束點,center,radius坐标值.并傳回新半徑,坐标值的球體.
*/
///<summary>set</summary>
///<param name ="center" type="Vector3">中心點坐标值</param>
///<param name ="radius" type="Number">Number球體半徑</param>
///<returns type="Sphere">傳回新半徑,坐标值的球體</returns>
set: function ( center, radius ) {
this.center.copy( center );
this.radius = radius;
return this; //傳回新半徑,坐标值的球體
},
///setFromPoints方法通過獲得Vector3對象組成的points數組中的到圓心距離最大的值又一次設定球體的半徑,通過可選參數optionalCenter用來設定球體的圓心.并傳回新半徑,坐标值的球體.
/// NOTE:注意假設給setFromPoints()方法設定了optionalCenter參數,points數組中數值到圓心的距離将會改變.
///<summary>setFromPoints</summary>
///<param name ="points" type="Vector3Array">Vector3對象組成的points數組</param>
///<param name ="optionalCenter" type="Vector3">可選參數,接收傳回結果,球體的中心點</param>
setFromPoints: function () {
var box = new THREE.Box3();
return function ( points, optionalCenter ) {
var center = this.center;
if ( optionalCenter !== undefined ) {
center.copy( optionalCenter );
} else {
box.setFromPoints( points ).center( center );
}
var maxRadiusSq = 0;
for ( var i = 0, il = points.length; i < il; i ++ ) {
maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) ); //求points數組中到圓心的最大值并指派給maxRadiusSq
this.radius = Math.sqrt( maxRadiusSq );
return this; //傳回新半徑,坐标值的球體
}(),
///copy方法用來複制球體的圓心,半徑,center,radius值.傳回新半徑,坐标值的球體
///<summary>copy</summary>
///<param name ="sphere" type="Sphere">球體</param>
copy: function ( sphere ) {
this.center.copy( sphere.center );
this.radius = sphere.radius;
///empty方法用來推斷球體的半徑是否小于等于0,用來推斷空間中半徑是0,或者小于0的球體.
///<summary>empty</summary>
///<returns type="Boolean">傳回true 或者 false</returns>
empty: function () {
return ( this.radius <= 0 ); //傳回true 或者 false
///containsPoint方法用來獲得參數point(一個Vector3的三維點坐标)是否在目前球體内.
///<summary>containsPoint</summary>
///<param name ="point" type="Vector3">一個Vector3的三維點坐标</param>
containsPoint: function ( point ) {
return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) ); //傳回true 或者 false
///distanceToPoint方法用來獲得三維空間内一點到Sphere球體對象表面的最小長度.
///<summary>distanceToPoint</summary>
///<param name ="point" type="Vector3">一個三維空間内的Vector3的三維點坐标</param>
///<returns type="Number">傳回三維空間内一點到Sphere球體對象表面的最小長度.</returns>
distanceToPoint: function ( point ) {
return ( point.distanceTo( this.center ) - this.radius ); //傳回三維空間内一點到Sphere球體對象表面的最小長度.
///intersectsSphere方法擷取目前球體是否與參數sphere球體對象相交,傳回true 或者 false
///<summary>intersectsSphere</summary>
///<param name ="sphere" type="Sphere">一個Sphere的球體</param>
intersectsSphere: function ( sphere ) {
var radiusSum = this.radius + sphere.radius;
return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum ); //傳回true 或者 false
///clampPoint方法用來通過參數point收縮球體.假設point在球體外,強制将point設定到球體表面,假設point在球體内,又一次設定球體半徑為point到目前球體半徑的距離.
///<summary>clampPoint</summary>
///<param name ="optionalTarget" type="Vector3">可選參數,接收傳回結果,傳回剪裁過的邊界點</param>
///<returns type="Vector3">傳回剪裁過的邊界點.</returns>
clampPoint: function ( point, optionalTarget ) {
var deltaLengthSq = this.center.distanceToSquared( point );
var result = optionalTarget || new THREE.Vector3();
result.copy( point );
if ( deltaLengthSq > ( this.radius * this.radius ) ) {
result.sub( this.center ).normalize();
result.multiplyScalar( this.radius ).add( this.center );
return result; // 傳回剪裁過的邊界點
///getBoundingBox方法傳回目前球體的Box3立方體邊界(這裡應該外切于球體的一個立方體)
/// 與Box3類中的getBoundingSphere()方法相應.
///<summary>getBoundingBox</summary>
///<param name ="optionalTarget" type="THREE.Box3()">可選參數,THREE.Box3()立方體對象,用來接收傳回值</param>
///<returns type="THREE.Sphere()">傳回目前球體的Box3立方體邊界(這裡應該外切于球體的一個立方體)</returns>
getBoundingBox: function ( optionalTarget ) {
var box = optionalTarget || new THREE.Box3();
box.set( this.center, this.center );
box.expandByScalar( this.radius );
return box; //傳回目前球體的Box3立方體邊界(這裡應該外切于球體的一個立方體)
///applyMatrix4方法通過傳遞matrix(旋轉,縮放,移動等變換矩陣)對目前Sphere球體對象的圓心和半徑,應用變換.
///<summary>applyMatrix4</summary>
///<param name ="matrix" type="Matrix4">(旋轉,縮放,移動等變換矩陣</param>
///<returns type="Boolean">傳回變換後的球體.</returns>
applyMatrix4: function ( matrix ) {
this.center.applyMatrix4( matrix );
this.radius = this.radius * matrix.getMaxScaleOnAxis();
return this; //傳回變換後的球體.
///translate方法用來通過參數offset,移動目前球體的位置.
///<summary>translate</summary>
///<param name ="offset" type="Vector3">偏移量</param>
///<returns type="Boolean">傳回新半徑,坐标值的球體</returns>
translate: function ( offset ) {
this.center.add( offset );
///equals方法用來獲得參數sphere(一個Sphere的球體)是否與目前球體全然相等,即圓心和半徑相等.
///<summary>equals</summary>
equals: function ( sphere ) {
return sphere.center.equals( this.center ) && ( sphere.radius === this.radius ); //傳回true 或者 false
/*clone方法
///clone方法克隆一個球體對象.
///<summary>clone</summary>
///<returns type="Sphere">傳回球體對象</returns>
clone: function () {
return new THREE.Sphere().copy( this ); //傳回球體對象
<a target="_blank" href="http://blog.csdn.net/omni360">轉載請保留此句:商域無疆 - 本部落格專注于 靈活開發及移動和物聯裝置研究:資料可視化、GOLANG、Html5、WEBGL、THREE.JS。否則,出自本部落格的文章拒絕轉載或再轉載,謝謝合作。</a>
下面代碼是THREE.JS 源代碼檔案裡Math/Line3.js檔案的凝視.
本文轉自mfrbuaa部落格園部落格,原文連結:http://www.cnblogs.com/mfrbuaa/p/5172867.html,如需轉載請自行聯系原作者