商域无疆 (http://blog.csdn.net/omni360/)

本文遵循“署名-非商业用途-保持一致”创作公用协议

转载请保留此句:商域无疆 -  本博客专注于 敏捷开发及移动和物联设备研究:数据可视化、GOLANG、Html5、WEBGL、THREE.JS,否则。出自本博客的文章拒绝转载或再转载,谢谢合作。

俺也是刚開始学,好多地儿肯定不正确还请见谅.

下面代码是THREE.JS 源代码文件里Math/Sphere.js文件的凝视.

很多其它更新在 : https://github.com/omni360/three.js.sourcecode/blob/master/Three.js

// File:src/math/Sphere.js

/**
* @author bhouston / http://exocortex.com
* @author mrdoob / http://mrdoob.com/
*/
/*
///Sphere对象的构造函数.用来在三维空间内创建一个球体对象.Sphere对象的功能函数採用
///定义构造的函数原型对象来实现.
///
/// 使用方法: var center = new Vector3(0,0,0),radius = 5; var sphere = new Sphere(center,radius);
///创建一个圆心是0,0,0半径是5的球体.
*/
///<summary>Sphere</summary>
///<param name ="center" type="Vector3">中心点坐标值</param>
///<param name ="radius" type="Number">Number球体半径</param>
THREE.Sphere = function ( center, radius ) { this.center = ( center !== undefined ) ? center : new THREE.Vector3(); //赋值或者初始化center
this.radius = ( radius !== undefined ) ? 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>
///<returns type="Sphere">返回新半径,坐标值的球体</returns>
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>
///<returns type="Sphere">返回新半径,坐标值的球体</returns>
copy: function ( sphere ) { this.center.copy( sphere.center );
this.radius = sphere.radius; return this; //返回新半径,坐标值的球体 }, /*
///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>
///<returns type="Boolean">返回true 或者 false</returns>
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>
///<returns type="Boolean">返回true 或者 false</returns>
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 ="point" type="Vector3">一个Vector3的三维点坐标</param>
///<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 ); return this; //返回新半径,坐标值的球体 }, /*
///equals方法用来获得參数sphere(一个Sphere的球体)是否与当前球体全然相等,即圆心和半径相等.
*/
///<summary>equals</summary>
///<param name ="sphere" type="Sphere">一个Sphere的球体</param>
///<returns type="Boolean">返回true 或者 false</returns>
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 ); //返回球体对象 } };

商域无疆 (http://blog.csdn.net/omni360/)

本文遵循“署名-非商业用途-保持一致”创作公用协议

转载请保留此句:商域无疆 -  本博客专注于 敏捷开发及移动和物联设备研究:数据可视化、GOLANG、Html5、WEBGL、THREE.JS。否则,出自本博客的文章拒绝转载或再转载,谢谢合作。

下面代码是THREE.JS 源代码文件里Math/Line3.js文件的凝视.

很多其它更新在 : https://github.com/omni360/three.js.sourcecode/blob/master/Three.js

three.js 源代码凝视(十四)Math/Sphere.js的更多相关文章

  1. three.js 源代码凝视(十六)Math/Frustum.js

    商域无疆 (http://blog.csdn.net/omni360/) 本文遵循"署名-非商业用途-保持一致"创作公用协议 转载请保留此句:商域无疆 -  本博客专注于 敏捷开发 ...

  2. three.js 源代码凝视(十五)Math/Plane.js

    商域无疆 (http://blog.csdn.net/omni360/) 本文遵循"署名-非商业用途-保持一致"创作公用协议 转载请保留此句:商域无疆 -  本博客专注于 敏捷开发 ...

  3. three.js 源代码凝视(十)Math/Line3.js

    商域无疆 (http://blog.csdn.net/omni360/) 本文遵循"署名-非商业用途-保持一致"创作公用协议 转载请保留此句:商域无疆 -  本博客专注于 敏捷开发 ...

  4. three.js 源代码凝视(七)Math/Euler.js

    商域无疆 (http://blog.csdn.net/omni360/) 本文遵循"署名-非商业用途-保持一致"创作公用协议 转载请保留此句:商域无疆 -  本博客专注于 敏捷开发 ...

  5. three.js 源代码凝视(九)Math/Matrix4.js

    商域无疆 (http://blog.csdn.net/omni360/) 本文遵循"署名-非商业用途-保持一致"创作公用协议 转载请保留此句:商域无疆 -  本博客专注于 敏捷开发 ...

  6. js加密(十四)mail.yw.gov.cn/ RSA

    1. url: http://mail.yw.gov.cn/ 2. target:登录js 3. 简单分析: 寻找加密js: 3.1 直接寻找加密的参数p是不好找的,所以我们试着去寻找一些更明显的参数 ...

  7. 第十四课:js操作节点的插入,复制,移除

    节点插入 appendChild方法,insertBefore方法是常用的两个节点插入方法,具体实现,请看js高级程序设计,或者自行百度. 这里提一下面试时经常会问到的问题,插入多个节点时,你是怎么插 ...

  8. js原生Ajax(十四)

    一.XMLHttpRequest    [使用XMLHttpRequest时,必须将html部署到web服务器中]1) 指定请求1.实例化eg: var http = new XMLHttpReque ...

  9. Ext JS学习第十四天 Ext基础之 Ext.DomHelper

    此文用来记录学习笔记   •我们已经学过了Element这个类,无疑是非常强大的,里面提供了丰富的方法供我们使用,但是Ext为了更加的方便我们去操作DOM元素,特提供了DomHelper这个辅助的工具 ...

随机推荐

  1. ThinkPHP 3.1.2 查询方式的一般使用1

    public function show(){ echo "访问了index模块下的show方法!!"; echo "欢迎你".$_GET['name'].'你 ...

  2. Linux设置高分辨率后无法进入X系统

    Vmware9.0中Xubuntu分辨率从800x600变更为1366x768后在用户输入密码登录后会自动退出x系统,出现这种情况时可以切换到命令行登录界面,然后将-/.config/xfce4/xf ...

  3. STL algorithm算法mismatch(37)

    mismatch原型: std::mismatch equality (1) template <class InputIterator1, class InputIterator2> p ...

  4. leetcode第一刷_Construct Binary Tree from Inorder and Postorder Traversal

    这道题是为数不多的感觉在读本科的时候见过的问题. 人工构造的过程是如何呢.兴许遍历最后一个节点一定是整棵树的根节点.从中序遍历中查找到这个元素,就能够把树分为两颗子树,这个元素左側的递归构造左子树,右 ...

  5. Tableau Server 8.0 升级到 8.3 过程记录

    一.使用账号(管理员权限),安装文件复制到服务器 二.检查维护状态 如果维护状态过期,更新到新版本会变成未授权. 先进Manage Product Keys刷新一下维护日期(其实不刷新也无所谓.到时候 ...

  6. 如何在macox下面配置集成ios和android游戏教程

    教程截图: 1.准备工作,配置开发环境: 开发环境:mac ox 10.7.3  +   xcode4.2  + ndk r7 + eclipse helios 部署环境:中兴v880  root过了 ...

  7. BZOJ 1711: [Usaco2007 Open]Dingin吃饭( 最大流 )

    将牛拆成两个点 i 和 i' 并连弧 , S 向每种 food 连边 , 每种 drink 向 T 连边 , 每种 food 向喜欢他的 cow 连边 到 i , 每种 drink 从喜欢它的 cow ...

  8. 用jmeter进行多用户并发压力测试 [转]

    近日manager要求对项目进行压力测试,开始对jmeter进行了研究.jmeter是Apache一个开源项目,可对各种项目进行测试,甚至包括junit. 测试要求如下,多用户同时登陆web应用程序, ...

  9. Sort list by merge sort

    使用归并排序对链表进行排序 O(nlgn) 的时间效率 /** * Definition for singly-linked list. * struct ListNode { * int val; ...

  10. (转)requirejs:杏仁的优化(almond)

    使用场景 什么情况下需要使用 almond 呢?假设你手头有个基于requirejs的小项目,所有业务代码加起来就几十K(压缩后可能更小).出于性能优化的考虑,你可能在想:如果能够去掉requirej ...