Three 平面(Plane)和 三维几何线段(Line3)

平面(Plane)

在三维空间中无限延伸的二维平面,平面方程用单位长度的法向量和常数表示为海塞法向量Hessian normal form形式。

构造器(Constructor)

Plane( normal : Vector3, constant : Float )

normal - (可选参数) 定义单位长度的平面法向量Vector3。默认值为 (1, 0, 0)

constant - (可选参数) 从原点到平面的有符号距离。 默认值为 0.

属性(Properties)

# .normal : Vector3

# .constant : Float

方法(Methods)

# .applyMatrix4 ( matrix : Matrix4, optionalNormalMatrix : Matrix3 ) : Plane

matrix - 要应用的四位矩阵(Matrix4)。

optionalNormalMatrix - (可选参数) 预先计算好的上述Matrix4参数的法线矩阵 Matrix3。

在平面上应用矩阵。矩阵必须是仿射齐次变换。

如果提供一个optionalNormalMatrix,可以这样创建: var optionalNormalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );

# .clone () : Plane

返回一个与当前平面有相同法线 normal,常量 constant 距离的平面。

# .coplanarPoint ( target : Vector3 ) : Vector3

target --- 结果会拷贝到该向量中。

返回一个共面点,通过原点的法向量在平面上投影算得。

# .copy ( plane : Plane ) : Plane

拷贝给定平面,将其中的法线 normal,距离常量 constant属性拷贝给该对象。

# .distanceToPoint ( point : Vector3 ) : Float

var plane1 = new THREE.Plane(new THREE.Vector3(0,1,0), -10); 
plane1.distanceToPoint(new THREE.Vector3(0,1,0))//返回-9

返回点point到平面的有符号距离。

# .distanceToSphere ( sphere : Sphere ) : Float

var plane = new THREE.Plane(new THREE.Vector3(0,1,0), -10);
var sphere = new THREE.Sphere(new THREE.Vector3(0,0,0), 5);
plane.distanceToSphere(sphere)//返回-15
//three.js distanceToSphere源码
distanceToSphere: function ( sphere ) {
    return this.distanceToPoint( sphere.center ) - sphere.radius;
},

返回球面 sphere 的边缘到平面的最短距离。

# .equals ( plane : Plane ) : Boolean

检查两个平面是否相等。(法线 normal 以及常量 constant 都相同)。

# .intersectLine ( line : Line3, target : Vector3 ) : Vector3

var line1 = new THREE.Line3(new THREE.Vector3(0,0,0), new THREE.Vector3(9,9,9)); 
var line2 = new THREE.Line3(new THREE.Vector3(0,0,0), new THREE.Vector3(11,11,11)); 
console.log(plane.intersectLine(line1))//返回undefined 
console.log(plane.intersectLine(line2))//返回Vector3 {x: 10, y: 10, z: 10}

line - 检测是否相交的三维几何线段 Line3。

target --- 结果将会写入该向量中。

返回给定线段和平面的交点。如果不相交则返回undefined。如果线与平面共面,则返回该线段的起始点。

# .intersectsBox ( box : Box3 ) : Boolean

box - 检查是否相交的包围盒 Box3。

确定该平面是否与给定3d包围盒Box3相交。

# .intersectsLine ( line : Line3 ) : Boolean

var line1 = new THREE.Line3(new THREE.Vector3(0,0,0), new THREE.Vector3(9,9,9)); 
var line2 = new THREE.Line3(new THREE.Vector3(0,0,0), new THREE.Vector3(11,11,11)); 
console.log(plane.intersectLine(line1))//返回false 
console.log(plane.intersectLine(line2))//返回true

line - 检查是否相交的三维线段 Line3。

测试线段是否与平面相交。

# .intersectsSphere ( sphere : Sphere ) : Boolean

sphere - 检查是否相交的球体 Sphere。

确定该平面是否与给定球体 Sphere 相交。

# .negate () : Plane

将法向量与常量求反(乘以-1)。

# .normalize () : Plane

//首先我们通过构造函数,并且两个法向量方向相同模长不同,因为返回的constant相同,实际上得到的是相同的平面,因为法向量默认是归一化了的 
var plane1 = new THREE.Plane(new THREE.Vector3(2,2,0), -20);
//constant: -20,normal: Vector3 {x: 2, y: 2, z: 0} 
var plane2 = new THREE.Plane(new THREE.Vector3(1,1,0), -20);
//constant: -20,normal: Vector3 {x: 1, y: 1, z: 0} 
//然后我们将其归一化,这是两个plane的constant,也会随着归一化的比例调整,所以实际效果的距离相差一倍。 
var plane_n1 = plane1.normalize();
//返回constant: -7.071067811865475,normal: Vector3 {x: 0.7071067811865475, y: 0.7071067811865475, z: 0} 
var plane_n2 = plane2.normalize();
//返回constant: -14.14213562373095,normal: Vector3 {x: 0.7071067811865475, y: 0.7071067811865475, z: 0}

归一化法向量 normal ,并相应的调整常量 constant数值。

# .projectPoint ( point : Vector3, target : Vector3 ) : Vector3

var plane = new THREE.Plane(new THREE.Vector3(0,1,0), -10); 
plane.projectPoint(new THREE.Vector3(1,1,1));//返回(1,10,1)

point - 需要投射到该平面的点。

target --- 在该平面上离投射点最近的点。

将一个点point投射到该平面上。

# .set ( normal : Vector3, constant : Float ) : Plane

new THREE.Plane().set(new THREE.Vector3(0,1,0), -10);

这里可要注意plane的法向量为new THREE.Vector3(0,1,0)代表平面的正方向是沿Y轴向上的,距离-10代表平面到原点的距离,符号代表和法向量的方向相反,所以这个这个平面在Y轴正方向。

normal - 单位长度的向量表示平面的法向量。

constant - 原点到平面有符号距离。默认值为 0

设置平面 normal 的法线和常量 constant 属性值。

# .setComponents ( x : Float, y : Float, z : Float, w : Float ) : Plane

x - 单位长度法向量的x值。

y - 单位长度法向量的y值。

z - 单位长度法向量的z值。

w - 原点沿法向量到平面常量 constant 距离。

new THREE.Plane().setComponents(0,1,0,-10);

设置定义平面的各个变量。

# .setFromCoplanarPoints ( a : Vector3, b : Vector3, c : Vector3 ) : Plane

a - 用于确定平面的第一个点。

b - 用于确定平面的第二个点。

c - 用于确定平面的第三个点。

new THREE.Plane().setFromNormalAndCoplanarPoint(new THREE.Vector3(0,1,0), new THREE.Vector3(10,10,10));

根据给定的三个点确定平面。如果三个点共线将会抛出错误。通过右手螺旋规则确定(向量叉乘)法向量 normal。

# .setFromNormalAndCoplanarPoint ( normal : Vector3, point : Vector3 ) : Plane this : Vector3

normal - 平面单位法向量

point - 平面上的点

通过平面上的一点以及法线确定原点到平面的最短距离(常量)。

# .translate ( offset : Vector3 ) : Plane

offset - 平移量

将平面平移给定向量大小,注意:这只会影响平面的常量不会影响平面的法向量。

三维几何线段(Line3)

用起点和终点表示的几何线段。

构造器(Constructor)

Line3( start : Vector3, end : Vector3 )

start - 线段的起始点。默认值为 (0, 0, 0)。

end - 线段的终点。默认值为 (0, 0, 0)。

创建一个三维几何线段 Line3。

属性(Properties)

# .start : Vector3

Vector3 表示线段的起点。

# .end : Vector3

Vector3 表示线段的终点

方法(Methods)

# .applyMatrix4 ( matrix : Matrix4 ) : Line3

对此线段应用矩阵变换。

# .at ( t : Float, target : Vector3 ) : Vector3

t - 使用值0-1返回沿线段的位置。

target --- 计算结果会被拷贝到target。

返回一个线段某一位置的向量,当 t = 0的时候返回起始点,当t = 1的时候返回终点。

# .clone () : Line3

返回一个与此线段拥有相同起始点 start 和 终点end 的线段。

# .closestPointToPoint ( point : Vector3, clampToLine : Boolean, target : Vector3 ) : Vector3

point - 用于计算线段上到该点最近的点。

clampToLine - 是否将结果限制在线段起始点和终点之间。

target --- 结果会拷贝到target。

返回线段上到point最近的点。如果参数 clampToLine 为true。返回值将会在线段之间。

# .closestPointToPointParameter ( point : Vector3, clampToLine : Boolean ) : Float

point - 用于计算返回值的点

clampToLine - 结果是否处于 [0, 1]之间。

返回一个基于点投影到线段上的点的参数。如果 clampToLine 为true则返回值将在0到1之间。

# .copy ( line : Line3 ) : Line3

拷贝传入线段的起始点 start 和终点 end 向量到当前线段。

# .delta ( target : Vector3 ) : Vector3

target --- 结果将会拷贝到target。

返回线段的向量。(终点end向量减去起始点start向量)。

# .distance () : Float

Returns the Euclidean distance (straight-line distance) between the line's start and end points.

# .distanceSq () : Float

返回起始点start和终点end的欧几里得距离Euclidean distance。(直线距离)

# .equals ( line : Line3 ) : Boolean

line - Line3 to compare with this one.

如果给定线段与当前线段的起始点start和终点end都相同则返回true。

# .getCenter ( target : Vector3 ) : Vector3

target --- 结果会写入target。

返回线段的中心点。

# .set ( start : Vector3, end : Vector3 ) : Line3

start - 设置线段的起点 start point。

end - 设置线段的终点 end point。

将传入的向量设置到线段的起始点和终点。

相关推荐
酷酷的崽7981 小时前
【数据结构】——原来排序算法搞懂这些就行,轻松拿捏
数据结构·算法·排序算法
八月的雨季 最後的冰吻2 小时前
C--字符串函数处理总结
c语言·前端·算法
阿拉伯的劳伦斯2924 小时前
LeetCode第一题(梦开始的地方)
数据结构·算法·leetcode
Mr_Xuhhh4 小时前
C语言深度剖析--不定期更新的第六弹
c语言·开发语言·数据结构·算法
吵闹的人群保持笑容多冷静4 小时前
2024CCPC网络预选赛 I. 找行李 【DP】
算法
桃酥4035 小时前
算法day22|组合总和 (含剪枝)、40.组合总和II、131.分割回文串
数据结构·c++·算法·leetcode·剪枝
山脚ice5 小时前
【Hot100】LeetCode—55. 跳跃游戏
算法·leetcode
桃酥4035 小时前
算法day21|回溯理论基础、77. 组合(剪枝)、216.组合总和III、17.电话号码的字母组合
java·数据结构·c++·算法·leetcode·剪枝
小丁爱养花5 小时前
DFS算法专题(一)——二叉树中的深搜【回溯与剪枝的初步注入】
java·开发语言·算法·leetcode·深度优先·剪枝
潮汐退涨月冷风霜5 小时前
决策树模型python代码实现
python·算法·决策树