|
@@ -8,36 +8,34 @@
|
|
|
<link type="text/css" rel="stylesheet" href="page.css" />
|
|
|
</head>
|
|
|
<body>
|
|
|
- <h1>[name]</h1>
|
|
|
+ <h1>二维向量([name])</h1>
|
|
|
|
|
|
<p class="desc">
|
|
|
- Class representing a 2D [link:https://en.wikipedia.org/wiki/Vector_space vector].
|
|
|
+ 表示2D [link:https://en.wikipedia.org/wiki/Vector_space vector](二维向量)的类。
|
|
|
|
|
|
- A 2D vector is an ordered pair of numbers (labeled x and y), which can be used to
|
|
|
- represent a number of things, such as:
|
|
|
+ 一个二维向量是一对有顺序的数字(标记为x和y),可用来表示很多事物,例如:
|
|
|
</p>
|
|
|
|
|
|
<ul>
|
|
|
<li>
|
|
|
- A point in 2D space (i.e. a position on a plane).
|
|
|
+ 一个位于二维空间中的点(例如一个在平面上的点)。
|
|
|
</li>
|
|
|
<li>
|
|
|
- A direction and length across a plane. In three.js the length will always be the
|
|
|
- [link:https://en.wikipedia.org/wiki/Euclidean_distance Euclidean distance]
|
|
|
- (straight-line distance) from (0, 0) to (x, y) and the direction is also
|
|
|
- measured from (0, 0) towards (x, y).
|
|
|
+ 一个平面上的方向与长度的定义。在three.js中,长度总是从(0, 0)到(x, y)的
|
|
|
+ [link:https://en.wikipedia.org/wiki/Euclidean_distance Euclidean distance](欧几里德距离,即直线距离),
|
|
|
+ 方向也是从(0, 0)到(x, y)的方向。
|
|
|
</li>
|
|
|
<li>
|
|
|
- Any arbitrary ordered pair of numbers.
|
|
|
+ 任意的、有顺序的一对数字。
|
|
|
</li>
|
|
|
</ul>
|
|
|
|
|
|
<p>
|
|
|
- There are other things a 2D vector can be used to represent, such as momentum
|
|
|
- vectors, complex numbers and so on, however these are the most common uses in three.js.
|
|
|
+ 其他的一些事物也可以使用二维向量进行表示,比如说动量矢量、复数等等;但以上这些是它在three.js中的常用用途。
|
|
|
</p>
|
|
|
|
|
|
- <h2>Example</h2>
|
|
|
+ <h2>示例</h2>
|
|
|
+
|
|
|
|
|
|
<code>
|
|
|
var a = new THREE.Vector2( 0, 1 );
|
|
@@ -49,132 +47,133 @@
|
|
|
</code>
|
|
|
|
|
|
|
|
|
- <h2>Constructor</h2>
|
|
|
+ <h2>构造函数</h2>
|
|
|
|
|
|
<h3>[name]( [param:Float x], [param:Float y] )</h3>
|
|
|
<p>
|
|
|
- [page:Float x] - the x value of the vector. Default is *0*.<br />
|
|
|
- [page:Float y] - the y value of the vector. Default is *0*.<br /><br />
|
|
|
+ [page:Float x] - 向量的x值,默认为*0*。<br />
|
|
|
+ [page:Float y] - 向量的y值,默认为*0*。<br /><br />
|
|
|
|
|
|
- Creates a new [name].
|
|
|
+ 创建一个新的[name]。
|
|
|
</p>
|
|
|
|
|
|
|
|
|
- <h2>Properties</h2>
|
|
|
+ <h2>属性</h2>
|
|
|
|
|
|
<h3>[property:Boolean isVector2]</h3>
|
|
|
<p>
|
|
|
- Used to check whether this or derived classes are Vector2s. Default is *true*.<br /><br />
|
|
|
+ 用于测试这个类或者派生类是否为Vector2,默认为*true*。<br /><br />
|
|
|
|
|
|
- You should not change this, as it is used internally for optimisation.
|
|
|
+ 你不应当对这个属性进行改变,因为它在内部使用,以用于优化。
|
|
|
</p>
|
|
|
|
|
|
<h3>[property:Float height]</h3>
|
|
|
- <p>Alias for [page:.y y].</p>
|
|
|
+ <p>[page:.y y]的别名。</p>
|
|
|
|
|
|
<h3>[property:Float width]</h3>
|
|
|
- <p>Alias for [page:.x x].</p>
|
|
|
+ <p>[page:.x x]的别名。</p>
|
|
|
|
|
|
<h3>[property:Float x]</h3>
|
|
|
|
|
|
<h3>[property:Float y]</h3>
|
|
|
|
|
|
|
|
|
- <h2>Methods</h2>
|
|
|
+ <h2>方法</h2>
|
|
|
|
|
|
<h3>[method:this add]( [param:Vector2 v] )</h3>
|
|
|
- <p>Adds [page:Vector2 v] to this vector.</p>
|
|
|
+ <p>将传入的向量[page:Vector2 v]和这个向量相加。</p>
|
|
|
|
|
|
<h3>[method:this addScalar]( [param:Float s] )</h3>
|
|
|
- <p>Adds the scalar value [page:Float s] to this vector's [page:.x x] and [page:.y y] values.</p>
|
|
|
+ <p>将传入的标量[page:Float s]和这个向量的[page:.x x]值、[page:.y y]值相加。</p>
|
|
|
|
|
|
<h3>[method:this addScaledVector]( [param:Vector2 v], [param:Float s] )</h3>
|
|
|
- <p>Adds the multiple of [page:Vector2 v] and [page:Float s] to this vector.</p>
|
|
|
+ <p>将所传入的[page:Vector2 v]与[page:Float s]相乘所得乘积和这个向量相加。</p>
|
|
|
|
|
|
<h3>[method:this addVectors]( [param:Vector2 a], [param:Vector2 b] )</h3>
|
|
|
- <p>Sets this vector to [page:Vector2 a] + [page:Vector2 b].</p>
|
|
|
+ <p>将该向量设置为 [page:Vector2 a] + [page:Vector2 b]。</p>
|
|
|
|
|
|
<h3>[method:Float angle]()</h3>
|
|
|
<p>
|
|
|
- Computes the angle in radians of this vector with respect to the positive x-axis.
|
|
|
+ 计算该向量相对于x轴正方向的弧度角度。
|
|
|
</p>
|
|
|
|
|
|
<h3>[method:this applyMatrix3]( [param:Matrix3 m] )</h3>
|
|
|
<p>
|
|
|
- Multiplies this vector (with an implicit 1 as the 3rd component) by m.
|
|
|
+ 将该向量乘以三阶矩阵m(第三个值隐式地为1)。
|
|
|
</p>
|
|
|
|
|
|
<h3>[method:this ceil]()</h3>
|
|
|
<p>
|
|
|
- The [page:.x x] and [page:.y y] components of the vector are rounded up to the nearest integer value.
|
|
|
+ 向量中的[page:.x x]分量和[page:.y y]分量向上取整为最接近的整数值。
|
|
|
</p>
|
|
|
|
|
|
<h3>[method:this clamp]( [param:Vector2 min], [param:Vector2 max] )</h3>
|
|
|
<p>
|
|
|
- [page:Vector2 min] - the minimum x and y values.<br />
|
|
|
- [page:Vector2 max] - the maximum x and y values in the desired range<br /><br />
|
|
|
+ [page:Vector2 min] - 在限制范围内,x和y的最小值。<br />
|
|
|
+ [page:Vector2 max] - 在限制范围内,x和y的最大值。<br /><br />
|
|
|
+
|
|
|
+ 如果该向量的x值或y值大于限制范围内最大x值或y值,则该值将会被所对应的值取代。<br /><br />
|
|
|
+ 如果该向量的x值或y值小于限制范围内最小x值或y值,则该值将会被所对应的值取代。
|
|
|
|
|
|
- If this vector's x or y value is greater than the max vector's x or y value, it is replaced by the corresponding value. <br /><br />
|
|
|
- If this vector's x or y value is less than the min vector's x or y value, it is replaced by the corresponding value.
|
|
|
</p>
|
|
|
|
|
|
<h3>[method:this clampLength]( [param:Float min], [param:Float max] )</h3>
|
|
|
<p>
|
|
|
- [page:Float min] - the minimum value the length will be clamped to <br />
|
|
|
- [page:Float max] - the maximum value the length will be clamped to<br /><br />
|
|
|
+ [page:Float min] - 长度将被限制为的最小值 <br />
|
|
|
+ [page:Float max] - 长度将被限制为的最大值<br /><br />
|
|
|
+
|
|
|
+ 如果向量长度大于最大值,则它将会被最大值所取代。<br /><br />
|
|
|
+ 如果向量长度小于最小值,则它将会被最小值所取代。
|
|
|
|
|
|
- If this vector's length is greater than the max value, it is replaced by the max value. <br /><br />
|
|
|
- If this vector's length is less than the min value, it is replaced by the min value.
|
|
|
</p>
|
|
|
|
|
|
<h3>[method:this clampScalar]( [param:Float min], [param:Float max] )</h3>
|
|
|
<p>
|
|
|
- [page:Float min] - the minimum value the components will be clamped to <br />
|
|
|
- [page:Float max] - the maximum value the components will be clamped to<br /><br />
|
|
|
+ [page:Float min] - 分量将被限制为的最小值 <br />
|
|
|
+ [page:Float max] - 分量将被限制为的最大值<br /><br />
|
|
|
+
|
|
|
+ 如果该向量的x值或y值大于最大值,则它们将被最大值所取代。<br /><br />
|
|
|
+ 如果该向量的x值或y值小于最小值,则它们将被最小值所取代。
|
|
|
|
|
|
- If this vector's x or y values are greater than the max value, they are replaced by the max value. <br /><br />
|
|
|
- If this vector's x or y values are less than the min value, they are replaced by the min value.
|
|
|
</p>
|
|
|
|
|
|
<h3>[method:Vector2 clone]()</h3>
|
|
|
<p>
|
|
|
- Returns a new Vector2 with the same [page:.x x] and [page:.y y] values as this one.
|
|
|
+ 返回一个新的Vector2,新的Vector2具有和当前这个向量相同的[page:.x x]和[page:.y y]。
|
|
|
</p>
|
|
|
|
|
|
<h3>[method:this copy]( [param:Vector2 v] )</h3>
|
|
|
<p>
|
|
|
- Copies the values of the passed Vector2's [page:.x x] and [page:.y y]
|
|
|
- properties to this Vector2.
|
|
|
+ 将所传入Vector2的[page:.x x]和[page:.y y]属性复制给这一Vector2。
|
|
|
</p>
|
|
|
|
|
|
<h3>[method:Float distanceTo]( [param:Vector2 v] )</h3>
|
|
|
- <p>Computes the distance from this vector to [page:Vector2 v].</p>
|
|
|
+ <p>计算该vector到传入的[page:Vector2 v]的距离。</p>
|
|
|
|
|
|
<h3>[method:Float manhattanDistanceTo]( [param:Vector2 v] )</h3>
|
|
|
<p>
|
|
|
- Computes the [link:https://en.wikipedia.org/wiki/Taxicab_geometry Manhattan distance] from this vector to [page:Vector2 v].
|
|
|
+ 计算该vector到传入的[page:Vector2 v]的曼哈顿距离([link:https://en.wikipedia.org/wiki/Taxicab_geometry Manhattan distance])。
|
|
|
</p>
|
|
|
|
|
|
<h3>[method:Float distanceToSquared]( [param:Vector2 v] )</h3>
|
|
|
<p>
|
|
|
- Computes the squared distance from this vector to [page:Vector2 v]. If you are just
|
|
|
- comparing the distance with another distance, you should compare the distance squared instead
|
|
|
- as it is slightly more efficient to calculate.
|
|
|
+ 计算该vector到传入的[page:Vector2 v]的平方距离。
|
|
|
+ 如果你只是将该距离和另一个距离进行比较,则应当比较的是距离的平方,
|
|
|
+ 因为它的计算效率会更高一些。
|
|
|
</p>
|
|
|
|
|
|
<h3>[method:this divide]( [param:Vector2 v] )</h3>
|
|
|
- <p>Divides this vector by [page:Vector2 v].</p>
|
|
|
+ <p>将该向量除以向量[page:Vector2 v]。</p>
|
|
|
|
|
|
<h3>[method:this divideScalar]( [param:Float s] )</h3>
|
|
|
<p>
|
|
|
- Divides this vector by scalar [page:Float s].<br />
|
|
|
- Sets vector to *( 0, 0 )* if [page:Float s] = 0.
|
|
|
+ 将该向量除以标量[page:Float s]。<br />
|
|
|
+ 如果传入的[page:Float s] = 0,则向量将被设置为*( 0, 0 )*。
|
|
|
</p>
|
|
|
|
|
|
<h3>[method:Float dot]( [param:Vector2 v] )</h3>
|
|
|
<p>
|
|
|
- Calculates the [link:https://en.wikipedia.org/wiki/Dot_product dot product] of this
|
|
|
- vector and [page:Vector2 v].
|
|
|
+ 计算该vector和所传入[page:Vector2 v]的点积([link:https://en.wikipedia.org/wiki/Dot_product dot product])。
|
|
|
</p>
|
|
|
|
|
|
<h3>[method:Float cross]( [param:Vector2 v] )</h3>
|
|
@@ -184,10 +183,12 @@
|
|
|
</p>
|
|
|
|
|
|
<h3>[method:Boolean equals]( [param:Vector2 v] )</h3>
|
|
|
- <p>Checks for strict equality of this vector and [page:Vector2 v].</p>
|
|
|
+ <p>检查该向量和[page:Vector2 v]的严格相等性。</p>
|
|
|
|
|
|
<h3>[method:this floor]()</h3>
|
|
|
- <p>The components of the vector are rounded down to the nearest integer value.</p>
|
|
|
+ <p>
|
|
|
+ 向量中的[page:.x x]分量和[page:.y y]分量向下取整为最接近的整数值。
|
|
|
+ </p>
|
|
|
|
|
|
<h3>[method:this fromArray]( [param:Array array], [param:Integer offset] )</h3>
|
|
|
<p>
|
|
@@ -207,26 +208,28 @@
|
|
|
|
|
|
<h3>[method:Float getComponent]( [param:Integer index] )</h3>
|
|
|
<p>
|
|
|
- [page:Integer index] - 0 or 1.<br /><br />
|
|
|
+ [page:Integer index] - 0 或 1<br /><br />
|
|
|
|
|
|
- If index equals 0 returns the [page:.x x] value. <br />
|
|
|
- If index equals 1 returns the [page:.y y] value.
|
|
|
+ 如果index值为0则返回[page:.x x]值。<br />
|
|
|
+ 如果index值为1则返回[page:.y y]值。
|
|
|
</p>
|
|
|
|
|
|
<h3>[method:Float length]()</h3>
|
|
|
- <p>Computes the [link:https://en.wikipedia.org/wiki/Euclidean_distance Euclidean length]
|
|
|
- (straight-line length) from (0, 0) to (x, y).</p>
|
|
|
+ <p>
|
|
|
+ 计算从(0, 0)到(x, y)的欧几里得长度
|
|
|
+ ([link:https://en.wikipedia.org/wiki/Euclidean_distance Euclidean length],即直线长度)。
|
|
|
+ </p>
|
|
|
|
|
|
<h3>[method:Float manhattanLength]()</h3>
|
|
|
<p>
|
|
|
- Computes the [link:http://en.wikipedia.org/wiki/Taxicab_geometry Manhattan length] of this vector.
|
|
|
+ 计算该向量的曼哈顿长度([link:http://en.wikipedia.org/wiki/Taxicab_geometry Manhattan length])。
|
|
|
</p>
|
|
|
|
|
|
<h3>[method:Float lengthSq]()</h3>
|
|
|
<p>
|
|
|
- Computes the square of the [link:https://en.wikipedia.org/wiki/Euclidean_distance Euclidean length]
|
|
|
- (straight-line length) from (0, 0) to (x, y). If you are comparing the lengths of
|
|
|
- vectors, you should compare the length squared instead as it is slightly more efficient to calculate.
|
|
|
+ 计算从(0, 0)到(x, y)的欧几里得长度
|
|
|
+ ([link:https://en.wikipedia.org/wiki/Euclidean_distance Euclidean length],即直线长度)的平方。
|
|
|
+ 如果你正在比较向量的长度,应当比较的是长度的平方,因为它的计算效率更高一些。
|
|
|
</p>
|
|
|
|
|
|
<h3>[method:this lerp]( [param:Vector2 v], [param:Float alpha] )</h3>
|
|
@@ -250,96 +253,94 @@
|
|
|
</p>
|
|
|
|
|
|
<h3>[method:this negate]()</h3>
|
|
|
- <p>Inverts this vector - i.e. sets x = -x and y = -y.</p>
|
|
|
+ <p>将向量取反,例如将x和y取相反数: x = -x , y = -y。</p>
|
|
|
|
|
|
<h3>[method:this normalize]()</h3>
|
|
|
<p>
|
|
|
- Converts this vector to a [link:https://en.wikipedia.org/wiki/Unit_vector unit vector] - that is, sets it equal to the vector with the same direction
|
|
|
- as this one, but [page:.length length] 1.
|
|
|
+ 将该向量转换为单位向量([link:https://en.wikipedia.org/wiki/Unit_vector unit vector]),也就是说,将该向量的方向设置为和原向量相同,但是其长度([page:.length length])为1。
|
|
|
</p>
|
|
|
|
|
|
<h3>[method:this max]( [param:Vector2 v] )</h3>
|
|
|
<p>
|
|
|
- If this vector's x or y value is less than [page:Vector2 v]'s x or y value, replace
|
|
|
- that value with the corresponding max value.
|
|
|
+ 如果该向量的x值或y值小于所传入[page:Vector2 v]的x值或y值,则将该值替换为相应的最大值。
|
|
|
</p>
|
|
|
|
|
|
<h3>[method:this min]( [param:Vector2 v] )</h3>
|
|
|
<p>
|
|
|
- If this vector's x or y value is greater than [page:Vector2 v]'s x or y value, replace
|
|
|
- that value with the corresponding min value.
|
|
|
+ 如果该向量的x值或y值大于所传入[page:Vector2 v]的x值或y值,则将该值替换为相应的最小值。
|
|
|
</p>
|
|
|
|
|
|
<h3>[method:this multiply]( [param:Vector2 v] )</h3>
|
|
|
- <p>Multiplies this vector by [page:Vector2 v].</p>
|
|
|
+ <p>将该向量与所传入的向量[page:Vector2 v]进行相乘。</p>
|
|
|
|
|
|
|
|
|
<h3>[method:this multiplyScalar]( [param:Float s] )</h3>
|
|
|
- <p>Multiplies this vector by scalar [page:Float s].</p>
|
|
|
+ <p>将该向量与所传入的标量[page:Float s]进行相乘。</p>
|
|
|
|
|
|
<h3>[method:this rotateAround]( [param:Vector2 center], [param:float angle] )</h3>
|
|
|
<p>
|
|
|
- [page:Vector2 center] - the point around which to rotate.<br />
|
|
|
- [page:float angle] - the angle to rotate, in radians.<br /><br />
|
|
|
+ [page:Vector2 center] - 将被围绕旋转的点。<br />
|
|
|
+ [page:float angle] - 将要旋转的角度,以弧度来表示。<br /><br />
|
|
|
|
|
|
- Rotates the vector around [page:Vector2 center] by [page:float angle] radians.
|
|
|
+ 将向量围绕着[page:Vector2 center]旋转[page:float angle]弧度。
|
|
|
</p>
|
|
|
|
|
|
<h3>[method:this round]()</h3>
|
|
|
- <p>The components of the vector are rounded to the nearest integer value.</p>
|
|
|
+ <p>
|
|
|
+ 向量中的[page:.x x]分量和[page:.y y]分量四舍五入取整为最接近的整数值。
|
|
|
+ </p>
|
|
|
|
|
|
<h3>[method:this roundToZero]()</h3>
|
|
|
<p>
|
|
|
- The components of the vector are rounded towards zero (up if negative, down if positive) to an integer value.
|
|
|
+ 向量中的分量朝向0取整数(若分量为负数则向上取整,若为正数则向下取整)。
|
|
|
</p>
|
|
|
|
|
|
<h3>[method:this set]( [param:Float x], [param:Float y] )</h3>
|
|
|
- <p>Sets the [page:.x x] and [page:.y y] components of this vector.</p>
|
|
|
+ <p>设置该向量的[page:.x x]和[page:.y y]分量。</p>
|
|
|
|
|
|
<h3>[method:null setComponent]( [param:Integer index], [param:Float value] )</h3>
|
|
|
<p>
|
|
|
- [page:Integer index] - 0 or 1.<br />
|
|
|
+ [page:Integer index] - 0 或 1<br />
|
|
|
[page:Float value] - [page:Float]<br /><br />
|
|
|
|
|
|
- If index equals 0 set [page:.x x] to [page:Float value]. <br />
|
|
|
- If index equals 1 set [page:.y y] to [page:Float value]
|
|
|
+ 如果index值为0则将[page:.x x]值设置为[page:Float value]。<br />
|
|
|
+ 如果index值为1则将[page:.y y]值设置为[page:Float value]
|
|
|
</p>
|
|
|
|
|
|
<h3>[method:this setLength]( [param:Float l] )</h3>
|
|
|
<p>
|
|
|
- Sets this vector to the vector with the same direction as this one, but [page:.length length]
|
|
|
- [page:Float l].
|
|
|
+ 将该向量的方向设置为和原向量相同,但是长度([page:.length length])为[page:Float l]。
|
|
|
</p>
|
|
|
|
|
|
<h3>[method:this setScalar]( [param:Float scalar] )</h3>
|
|
|
<p>
|
|
|
- Sets the [page:.x x] and [page:.y y] values of this vector both equal to [page:Float scalar].
|
|
|
+ 将该向量的[page:.x x]、[page:.y y]值同时设置为传入的[page:Float scalar]。
|
|
|
</p>
|
|
|
|
|
|
<h3>[method:this setX]( [param:Float x] )</h3>
|
|
|
- <p>Replaces this vector's [page:.x x] value with [page:Float x].</p>
|
|
|
+ <p>将向量中的[page:.x x]值替换为[page:Float x]。</p>
|
|
|
|
|
|
<h3>[method:this setY]( [param:Float y] )</h3>
|
|
|
- <p>Replaces this vector's [page:.y y] value with [page:Float y].</p>
|
|
|
+ <p>将向量中的[page:.y y]值替换为[page:Float y]。</p>
|
|
|
|
|
|
<h3>[method:this sub]( [param:Vector2 v] )</h3>
|
|
|
- <p>Subtracts [page:Vector2 v] from this vector.</p>
|
|
|
+ <p>从该向量减去向量[page:Vector2 v]。</p>
|
|
|
|
|
|
<h3>[method:this subScalar]( [param:Float s] )</h3>
|
|
|
- <p>Subtracts [page:Float s] from this vector's [page:.x x] and [page:.y y] components.</p>
|
|
|
+ <p>从该向量的[page:.x x]和[page:.y y]中减去标量[page:Float s]。</p>
|
|
|
|
|
|
<h3>[method:this subVectors]( [param:Vector2 a], [param:Vector2 b] )</h3>
|
|
|
- <p>Sets this vector to [page:Vector2 a] - [page:Vector2 b].</p>
|
|
|
+ <p>将该向量设置为[page:Vector2 a] - [page:Vector2 b]。</p>
|
|
|
|
|
|
<h3>[method:Array toArray]( [param:Array array], [param:Integer offset] )</h3>
|
|
|
<p>
|
|
|
- [page:Array array] - (optional) array to store the vector to. If this is not provided, a new array will be created.<br />
|
|
|
- [page:Integer offset] - (optional) optional offset into the array.<br /><br />
|
|
|
+ [page:Array array] - (可选)被用于存储向量的数组。如果这个值没有传入,则将创建一个新的数组。<br />
|
|
|
+ [page:Integer offset] - (可选) 数组中元素的偏移量。<br /><br />
|
|
|
|
|
|
- Returns an array [x, y], or copies x and y into the provided [page:Array array].
|
|
|
+ 返回一个数组[x, y],或者将x和y复制到所传入的[page:Array array]中。
|
|
|
</p>
|
|
|
|
|
|
- <h2>Source</h2>
|
|
|
+ <h2>源代码</h2>
|
|
|
|
|
|
[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
|
|
|
</body>
|