商域无疆 (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. Python模块概念

    补充:生成器表达式 将列表生成器的中括号改为小括号就是生成器表达式 res = [i for i in range(10) if i > 5]  #  列表生成式 res = (i for i ...

  2. dbfread报错ValueError错误解决方法

    问题 我在用dbfread处理.dbf数据的时候出现了报错 ValueError("could not convert string to float: b'.'",) 然后查找. ...

  3. Aizu-ALDS1_3_A:Stack

    D - Stack Write a program which reads an expression in the Reverse Polish notation and prints the co ...

  4. grunt---grunt_test 测试用例

    说明: http://www.gruntjs.net/getting-started --grunt快速入门(创建package.json和Gruntfile.js准备一份新的 Grunt 项目一般需 ...

  5. python+selenium 鼠标事件操作

    一.前言 除了可以使用 click( ) 来模拟鼠标的单击操作,现在Web产品中还提供了更丰富的鼠标交互方式,例如鼠标右键.双击.悬停.拖动等功能,在WebDriver中,将这些关于鼠标操作的方法都封 ...

  6. centos 7安装libreoffice

    centos 7安装libreoffice Centos下的LibreOffice安装: 关键字: LibreOffice , sdk ,汉化  ,解压 安装Centos7之后,系统安装了libreo ...

  7. 【LeetCode】Same Tree(相同的树)

    这道题是LeetCode里的第100道题. 这是题目: 给定两个二叉树,编写一个函数来检验它们是否相同. 如果两个树在结构上相同,并且节点具有相同的值,则认为它们是相同的. 示例 1: 输入: 1 1 ...

  8. 【bzoj4519】[Cqoi2016]不同的最小割 分治+最小割

    题目描述 学过图论的同学都知道最小割的概念:对于一个图,某个对图中结点的划分将图中所有结点分成两个部分,如果结点s,t不在同一个部分中,则称这个划分是关于s,t的割.对于带权图来说,将所有顶点处在不同 ...

  9. Kubernetes对象

    Kubernetes对象 在之前的文章已经讲到了很多Kubernets对象,包括pod,service,deployment等等.Kubernets对象是一种持久化,表示集群状态的实体.它是一种声明式 ...

  10. 【Codeforces Round #505 (Div. 1 + Div. 2) 】

    A:https://www.cnblogs.com/myx12345/p/9843966.html B: C:https://www.cnblogs.com/myx12345/p/9844084.ht ...