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

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

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

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

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

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

// File:src/math/Plane.js

/**
* @author bhouston / http://exocortex.com
*/ /*
///Plane对象的构造函数.用来在三维空间内创建一个法线向量为normal,从原点到平面的距离为constant的无限延展的二维平面对象.Plane对象的功能函数採用
///定义构造的函数原型对象来实现.
///
/// 使用方法: var normal = new Vector3(0,0,0),constant = 5.5; var Plane = new Plane(normal,constant);
///创建一个法线向量是0,0,0原点到平面的距离是5.5的二维平面.
*/
///<summary>Plane</summary>
///<param name ="normal" type="Vector3">平面法线向量</param>
///<param name ="constant" type="Number">Number二维平面离原点的距离</param>
THREE.Plane = function ( normal, constant ) { this.normal = ( normal !== undefined ) ? normal : new THREE.Vector3( 1, 0, 0 ); //赋值或者初始化normal
this.constant = ( constant !== undefined ) ? constant : 0; //赋值或者初始化constant }; /****************************************
****以下是Plane对象提供的功能函数.
****************************************/
THREE.Plane.prototype = { constructor: THREE.Plane, //构造器,返回对创建此对象的Plane函数的引用 /*
///set方法用来又一次设置二维平面的法线向量normal,原点到平面的距离constant,并返回新的二维平面.
*/
///<summary>set</summary>
///<param name ="normal" type="Vector3">平面法线向量</param>
///<param name ="constant" type="Number">Number二维平面离原点的距离</param>
///<returns type="Plane">返回新的二维平面</returns>
set: function ( normal, constant ) { this.normal.copy( normal );
this.constant = constant; return this; //返回新的二维平面 }, /*
///setComponents方法用来通过x,y,z,w分量又一次设置二维平面的法线向量normal,原点到平面的距离constant,并返回新的二维平面.
*/
///<summary>setComponents</summary>
///<param name ="normal" type="Vector3">平面法线向量</param>
///<param name ="x" type="Number">平面法线向量x坐标</param>
///<param name ="y" type="Number">平面法线向量y坐标</param>
///<param name ="z" type="Number">平面法线向量z坐标</param>
///<param name ="w" type="Number">Number二维平面离原点的距离w</param>
///<returns type="Plane">返回新的二维平面</returns>
setComponents: function ( x, y, z, w ) { this.normal.set( x, y, z );
this.constant = w; return this; //返回新的二维平面 }, /*
///setFromNormalAndCoplanarPoint方法用来通过參数normal(平面法线向量)和參数point(共面的点)又一次设置二维平面的法线向量normal,原点到平面的距离constant,并返回新的二维平面.
*/
///<summary>setFromNormalAndCoplanarPoint</summary>
///<param name ="normal" type="Vector3">平面法线向量</param>
///<param name ="point" type="Vector3">共面的点</param>
///<returns type="Plane">返回新的二维平面</returns>
setFromNormalAndCoplanarPoint: function ( normal, point ) { this.normal.copy( normal );
//以下point.dot()方法仅仅接收this.normal,不接收normal,this.normal是被规范化的,是单位向量
this.constant = - point.dot( this.normal ); // must be this.normal, not normal, as this.normal is normalized return this; //并返回新的二维平面 }, /*
///setFromCoplanarPoints方法用来通过共面的点a,b,c又一次设置二维平面的法线向量normal,原点到平面的距离constant,并返回新的二维平面.
/// NOTE:setFromCoplanarPoints方法接受的3个点a,b,c,须要依照逆时针方向的顺序传入,来确定发现的方向.
*/
///<summary>setFromCoplanarPoints</summary>
///<param name ="a" type="Vector3">共面的点a</param>
///<param name ="b" type="Vector3">共面的点b</param>
///<param name ="c" type="Vector3">共面的点c</param>
///<returns type="Plane">返回新的二维平面</returns>
setFromCoplanarPoints: function () { var v1 = new THREE.Vector3();
var v2 = new THREE.Vector3(); return function ( a, b, c ) { var normal = v1.subVectors( c, b ).cross( v2.subVectors( a, b ) ).normalize(); //先得到向量c,b的差,通过cross方法获得向量a,b差的交叉乘积(交叉乘积垂直于向量a,b所在的平面),然后在调用normalize()方法获得单位向量. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)? //NOTE: 假设法向量normal是0,会产生一个无效的平面对象. this.setFromNormalAndCoplanarPoint( normal, a ); //setFromNormalAndCoplanarPoint方法用来通过參数normal(平面法线向量)和參数point(共面的点)又一次设置二维平面的法线向量normal,原点到平面的距离constant,并返回新的二维平面. return this; //返回新的二维平面 }; }(), /*
///copy方法用来复制二维平面的法线向量normal,原点到平面的距离constant值.返回新的二维平面
///TODO: copy方法和clone方法有什么不同?
*/
///<summary>copy</summary>
///<param name ="Plane" type="Plane">二维平面</param>
///<returns type="Plane">返回新的二维平面</returns>
copy: function ( plane ) { this.normal.copy( plane.normal );
this.constant = plane.constant; return this; //返回新的二维平面 }, /*
///normalize方法用来规范化法线向量,并调整constant常量的值(获得单位平面).
*/
///<summary>normalize</summary>
///<returns type="Plane">返回规范化后的二维平面(获得单位平面)</returns>
normalize: function () { // Note: will lead to a divide by zero if the plane is invalid.
// NOTE: 注意假设平面无效将产生除数是0的错误. var inverseNormalLength = 1.0 / this.normal.length();
this.normal.multiplyScalar( inverseNormalLength );
this.constant *= inverseNormalLength; return this; //返回规范化的二维平面(获得单位平面) }, /*
///negate方法用来翻转法线,获得当前平面的背面,
*/
///<summary>negate</summary>
///<returns type="Plane">返回当前平面的背面</returns>
negate: function () { this.constant *= - 1;
this.normal.negate(); //翻转法线,Vector3.negate方法将当前三维向量的(x,y,z)坐标值若为负数时,返回正数. 而当前三维向量的(x,y,z)坐标值若为正数时,返回负数. return this; //返回当前平面的背面 }, /*
///distanceToPoint方法用来获得三维空间内一点到Plane二维平面对象表面的最小长度.
*/
///<summary>distanceToPoint</summary>
///<param name ="point" type="Vector3">一个三维空间内的Vector3的三维点坐标</param>
///<returns type="Number">返回三维空间内一点到Plane二维平面对象表面的最小长度.</returns>
distanceToPoint: function ( point ) { return this.normal.dot( point ) + this.constant; //返回三维空间内一点到Plane二维平面对象表面的最小长度 }, /*
///distanceToPoint方法用来获得Plane二维平面对象到三维空间内一个球体表面的最小长度.()
*/
///<summary>distanceToPoint</summary>
///<param name ="sphere" type="Sphere">一个三维空间内的Sphere的球体对象</param>
///<returns type="Number">返回三维空间内Plane二维平面对象到三维空间内一个球体表面的最小长度.</returns>
distanceToSphere: function ( sphere ) { return this.distanceToPoint( sphere.center ) - sphere.radius; //返回三维空间内Plane二维平面对象到三维空间内一个球体表面的最小长度 }, /*
///projectPoint方法返回三维空间中一点到当前平面的投影.点到面上的投影等于从參数point到平面上的垂足,所以从垂足画条线到点垂直于平面.
*/
///<summary>projectPoint</summary>
///<param name ="point" type="Vector3">Vector3三维向量</param>
///<param name ="optionalTarget" type="Vector3">可选參数,接收返回结果</param>
///<returns type="Number">返回点到平面的投影</returns>
projectPoint: function ( point, optionalTarget ) { return this.orthoPoint( point, optionalTarget ).sub( point ).negate(); //调用orthoPoint()方法,减去point,返回取反的结果 }, /*
///orthoPoint方法返回一个与当前二维平面对象法线向量方向同样,与參数point到平面距离相等大小的向量(垂足).假设设置了optionalTarget參数,将结果保存在optionalTarget里.
*/
///<summary>orthoPoint</summary>
///<param name ="point" type="Vector3">Vector3三维向量</param>
///<param name ="optionalTarget" type="Vector3">可选參数,接收返回结果</param>
///<returns type="Vector3">返回一个与当前二维平面对象法线向量方向同样,与參数point到平面距离相等大小的向量(垂足).</returns>
orthoPoint: function ( point, optionalTarget ) { var perpendicularMagnitude = this.distanceToPoint( point ); //获得平面到參数point的距离,赋值给prependicularMagnitude var result = optionalTarget || new THREE.Vector3(); //生命变量resault,用来存放结果
return result.copy( this.normal ).multiplyScalar( perpendicularMagnitude ); //调用multiplyScalar(perpendicularMagnitude)方法,将当前二维平面的法向量的分量x,y,z分别乘以获得平面到參数point的距离.最后返回计算结果. }, /*
///isIntersectionLine方法获取当前二维平面是否与參数line相交,返回true 或者 false
*/
///<summary>isIntersectionLine</summary>
///<param name ="line" type="Line3">三维空间中的线Line3</param>
///<returns type="Boolean">返回true 或者 false</returns>
isIntersectionLine: function ( line ) { // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
// NOTE:isIntersectionLine()是測试线和面是否相交,不是误以为线和面是否共面 var startSign = this.distanceToPoint( line.start );
var endSign = this.distanceToPoint( line.end ); return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 ); //返回true 或者 false }, /*
///intersectLine方法获取当前二维平面与參数line相交的交点,假设和參数Line不相交返回undefined,假设线和当前二维平面共面返回线的起点.
*/
///<summary>isIntersectionLine</summary>
///<param name ="line" type="Line3">三维空间中的线Line3</param>
///<param name ="optionalTarget" type="Vector3">可选參数,接收返回结果</param>
///<returns type="Boolean">返回当前二维平面与參数line相交的交点,假设和參数Line不相交或其他未知返回undefined,假设线和当前二维平面共面返回线的起点.</returns>
intersectLine: function () { var v1 = new THREE.Vector3(); return function ( line, optionalTarget ) { var result = optionalTarget || new THREE.Vector3(); var direction = line.delta( v1 ); var denominator = this.normal.dot( direction ); if ( denominator == 0 ) { // line is coplanar, return origin
// 假设线和当前二维平面共面返回线的起点
if ( this.distanceToPoint( line.start ) == 0 ) { return result.copy( line.start ); } // Unsure if this is the correct method to handle this case.
// 假设其他未知返回undefined
return undefined; } var t = - ( line.start.dot( this.normal ) + this.constant ) / denominator; if ( t < 0 || t > 1 ) { return undefined; //假设和參数Line不相交返回undefined } return result.copy( direction ).multiplyScalar( t ).add( line.start ); //返回当前二维平面与參数line相交的交点 }; }(), /*
///coplanarPoint方法获取当前二维平面的法线向量到当前二维平面投影(垂足,与当前平面的共面的点).
///TODO:这里没有弄明确,有时间在弄清楚,高中几何都快忘光了,钻牛角尖了.只是知道在以下应用变换时调用了.
*/
///<summary>coplanarPoint</summary>
///<param name ="optionalTarget" type="Vector3">可选參数,接收返回结果</param>
///<returns type="Boolean">返回共面的点.</returns>
coplanarPoint: function ( optionalTarget ) { var result = optionalTarget || new THREE.Vector3();
return result.copy( this.normal ).multiplyScalar( - this.constant ); //返回共面的点 }, /*
///applyMatrix4方法通过传递matrix(旋转,缩放,移动等变换矩阵)对当前Plane二维平面对象的法线向量normal和,应用变换.
*/
///<summary>applyMatrix4</summary>
///<param name ="matrix" type="Matrix4">(旋转,缩放,移动等变换矩阵</param>
///<param name ="optionalNormalMatrix" type="Matrix3">可选參数,假设设置了就会对法线应用(旋转,缩放,移动等变换矩阵</param>
///<returns type="Boolean">返回变换后的二维平面.</returns>
applyMatrix4: function () { var v1 = new THREE.Vector3();
var v2 = new THREE.Vector3();
var m1 = new THREE.Matrix3(); return function ( matrix, optionalNormalMatrix ) { // compute new normal based on theory here:
// http://www.songho.ca/opengl/gl_normaltransform.html
var normalMatrix = optionalNormalMatrix || m1.getNormalMatrix( matrix );
var newNormal = v1.copy( this.normal ).applyMatrix3( normalMatrix ); var newCoplanarPoint = this.coplanarPoint( v2 ); //获得共面的点
newCoplanarPoint.applyMatrix4( matrix ); this.setFromNormalAndCoplanarPoint( newNormal, newCoplanarPoint ); //setFromNormalAndCoplanarPoint方法用来通过參数normal(平面法线向量)和參数point(共面的点)又一次设置二维平面的法线向量normal,原点到平面的距离constant,并返回新的二维平面. return this; //返回变换后的二维平面 }; }(), /*
///translate方法用来通过參数offset,移动当前二维平面的位置.
*/
///<summary>translate</summary>
///<param name ="offset" type="Vector3">偏移量</param>
///<returns type="Boolean">返回新的二维平面</returns>
translate: function ( offset ) { this.constant = this.constant - offset.dot( this.normal ); return this; //返回新的二维平面 }, /*
///equals方法用来获得參数Plane(一个Plane的二维平面)是否与当前二维平面全然相等,即法线向量normal和半径相等.
*/
///<summary>equals</summary>
///<param name ="Plane" type="Plane">一个Plane的二维平面</param>
///<returns type="Boolean">返回true 或者 false</returns>
equals: function ( plane ) { return plane.normal.equals( this.normal ) && ( plane.constant == this.constant ); //返回true 或者 false }, /*clone方法
///clone方法克隆一个二维平面对象.
*/
///<summary>clone</summary>
///<returns type="Plane">返回二维平面对象</returns>
clone: function () { return new THREE.Plane().copy( this ); //返回二维平面对象 } };

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

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

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

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

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

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

  1. Nodejs学习笔记(十五)—Node.js + Koa2 构建网站简单示例

    前言 前面一有写到一篇Node.js+Express构建网站简单示例:http://www.cnblogs.com/zhongweiv/p/nodejs_express_webapp.html 这篇还 ...

  2. Nodejs学习笔记(十五)--- Node.js + Koa2 构建网站简单示例

    目录 前言 搭建项目及其它准备工作 创建数据库 创建Koa2项目 安装项目其它需要包 清除冗余文件并重新规划项目目录 配置文件 规划示例路由,并新建相关文件 实现数据访问和业务逻辑相关方法 编写mys ...

  3. [转]Nodejs学习笔记(十五)--- Node.js + Koa2 构建网站简单示例

    本文转自:https://www.cnblogs.com/zhongweiv/p/nodejs_koa2_webapp.html 目录 前言 搭建项目及其它准备工作 创建数据库 创建Koa2项目 安装 ...

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

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

  5. three.js 源代码凝视(十四)Math/Sphere.js

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

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

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

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

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

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

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

  9. Python+Selenium笔记(十五)调用JS

    (一) 方法 方法 简单说明 execute_async_script(script, args) 异步执行JS代码 script:被执行的JS代码 args:js代码中的任意参数 execute_s ...

随机推荐

  1. LeetCode(72) Edit Distance

    题目 Given two words word1 and word2, find the minimum number of steps required to convert word1 to wo ...

  2. 也来“玩”Metro UI之磁贴(二)

    继昨天的“也来“玩”Metro UI之磁贴(一)”之后,还不过瘾,今天继续“玩”吧——今天把单选的功能加进来,还有磁贴的内容,还加了发光效果(CSS3,IE9+浏览器),当然,还是纯CSS,真的要感谢 ...

  3. 【Luogu】P2759奇怪的函数(二分)

    题目链接 看了题解之后突然发现这题简直是水题.然而不看题解就想不出来.为什么呢? len(x)=log10(x)+1 于是二分寻找x. #include<iostream> #includ ...

  4. POJ 2699 The Maximum Number of Strong Kings ——网络流

    一定存在一种最优方案,使得分数前几个人是SK 所以我们可以二分答案或者枚举,然后就是经典的网络流建模. 另:输入很Excited #include <cstdio> #include &l ...

  5. BZOJ2288 【POJ Challenge】生日礼物 【堆 + 链表】

    题目 ftiasch 18岁生日的时候,lqp18_31给她看了一个神奇的序列 A1, A2, ..., AN. 她被允许选择不超过 M 个连续的部分作为自己的生日礼物. 自然地,ftiasch想要知 ...

  6. 【bzoj1193】[HNOI2006]马步距离

    [HNOI2006]马步距离 Description Input 只包含4个整数,它们彼此用空格隔开,分别为xp,yp,xs,ys.并且它们的都小于10000000. Output 含一个整数,表示从 ...

  7. Hadoop 3.1.0 在 Ubuntu 16.04 上的安装过程

    安装过程主要参考官方文档: http://hadoop.apache.org/docs/current/hadoop-project-dist/hadoop-common/SingleCluster. ...

  8. 洛谷 P 1119 灾后重建

    题目背景 B地区在地震过后,所有村庄都造成了一定的损毁,而这场地震却没对公路造成什么影响.但是在村庄重建好之前,所有与未重建完成的村庄的公路均无法通车.换句话说,只有连接着两个重建完成的村庄的公路才能 ...

  9. bigdata related

    hive: http://lxw1234.com/archives/2015/07/413.htm 搜狗实验室数据集: https://www.sogou.com/labs/resource/list ...

  10. Bruce Eckel:编程生涯

    大家总是问一个错误的问题:“我应该学习C++还是Java?”在本文中,我将告诉大伙儿:对于选择编程生涯真正需要关注的是哪些问题. 请注意,这篇文章的目标读者并不是那些已经做出自己选择的人.(对于这些人 ...