1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348
|
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<base href="../../../" />
<script src="list.js"></script>
<script src="page.js"></script>
<link type="text/css" rel="stylesheet" href="page.css" />
</head>
<body>
<h1>[name]</h1>
<p class="desc">
Class representing a 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:
</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).
</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.
</p>
<h2>Example</h2>
<code>
var a = new THREE.Vector2( 0, 1 );
//no arguments; will be initialised to (0, 0)
var b = new THREE.Vector2( );
var d = a.distanceTo( b );
</code>
<h2>Constructor</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 />
Creates a new [name].
</p>
<h2>Properties</h2>
<h3>[property:Boolean isVector2]</h3>
<p>
Used to check whether this or derived classes are Vector2s. Default is *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>
<h3>[property:Float width]</h3>
<p>Alias for [page:.x x].</p>
<h3>[property:Float x]</h3>
<h3>[property:Float y]</h3>
<h2>Methods</h2>
<h3>[method:this add]( [param:Vector2 v] )</h3>
<p>Adds [page:Vector2 v] to this vector.</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>
<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>
<h3>[method:this addVectors]( [param:Vector2 a], [param:Vector2 b] )</h3>
<p>Sets this vector to [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.
</p>
<h3>[method:this applyMatrix3]( [param:Matrix3 m] )</h3>
<p>
Multiplies this vector (with an implicit 1 as the 3rd component) by m.
</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.
</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 />
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 />
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 />
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.
</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.
</p>
<h3>[method:Float distanceTo]( [param:Vector2 v] )</h3>
<p>Computes the distance from this vector to [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].
</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.
</p>
<h3>[method:this divide]( [param:Vector2 v] )</h3>
<p>Divides this vector by [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.
</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].
</p>
<h3>[method:Float cross]( [param:Vector2 v] )</h3>
<p>
Calculates the [link:https://en.wikipedia.org/wiki/Cross_product cross product] of this
vector and [page:Vector2 v]. Note that a 'cross-product' in 2D is not well-defined. This function computes a geometric cross-product often used in 2D graphics
</p>
<h3>[method:Boolean equals]( [param:Vector2 v] )</h3>
<p>Checks for strict equality of this vector and [page:Vector2 v].</p>
<h3>[method:this floor]()</h3>
<p>The components of the vector are rounded down to the nearest integer value.</p>
<h3>[method:this fromArray]( [param:Array array], [param:Integer offset] )</h3>
<p>
[page:Array array] - the source array.<br />
[page:Integer offset] - (optional) offset into the array. Default is 0.<br /><br />
Sets this vector's [page:.x x] value to be array[ offset ] and [page:.y y] value to be array[ offset + 1 ].
</p>
<h3>[method:this fromBufferAttribute]( [param:BufferAttribute attribute], [param:Integer index] )</h3>
<p>
[page:BufferAttribute attribute] - the source attribute.<br />
[page:Integer index] - index in the attribute.<br /><br />
Sets this vector's [page:.x x] and [page:.y y] values from the [page:BufferAttribute attribute].
</p>
<h3>[method:Float getComponent]( [param:Integer index] )</h3>
<p>
[page:Integer index] - 0 or 1.<br /><br />
If index equals 0 returns the [page:.x x] value. <br />
If index equals 1 returns the [page:.y y] value.
</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>
<h3>[method:Float manhattanLength]()</h3>
<p>
Computes the [link:http://en.wikipedia.org/wiki/Taxicab_geometry Manhattan length] of this vector.
</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.
</p>
<h3>[method:this lerp]( [param:Vector2 v], [param:Float alpha] )</h3>
<p>
[page:Vector2 v] - [page:Vector2] to interpolate towards.<br />
[page:Float alpha] - interpolation factor, typically in the closed interval [0, 1].<br /><br />
Linearly interpolates between this vector and [page:Vector2 v], where alpha is the
percent distance along the line - alpha = 0 will be this vector, and alpha = 1 will be [page:Vector2 v].
</p>
<h3>[method:this lerpVectors]( [param:Vector2 v1], [param:Vector2 v2], [param:Float alpha] )</h3>
<p>
[page:Vector2 v1] - the starting [page:Vector2].<br />
[page:Vector2 v2] - [page:Vector2] to interpolate towards.<br />
[page:Float alpha] - interpolation factor, typically in the closed interval [0, 1].<br /><br />
Sets this vector to be the vector linearly interpolated between [page:Vector2 v1] and
[page:Vector2 v2] where alpha is the percent distance along the line connecting the two vectors
- alpha = 0 will be [page:Vector2 v1], and alpha = 1 will be [page:Vector2 v2].
</p>
<h3>[method:this negate]()</h3>
<p>Inverts this vector - i.e. sets x = -x and 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.
</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.
</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.
</p>
<h3>[method:this multiply]( [param:Vector2 v] )</h3>
<p>Multiplies this vector by [page:Vector2 v].</p>
<h3>[method:this multiplyScalar]( [param:Float s] )</h3>
<p>Multiplies this vector by scalar [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 />
Rotates the vector around [page:Vector2 center] by [page:float angle] radians.
</p>
<h3>[method:this round]()</h3>
<p>The components of the vector are rounded to the nearest integer value.</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.
</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>
<h3>[method:null setComponent]( [param:Integer index], [param:Float value] )</h3>
<p>
[page:Integer index] - 0 or 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]
</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].
</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].
</p>
<h3>[method:this setX]( [param:Float x] )</h3>
<p>Replaces this vector's [page:.x x] value with [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>
<h3>[method:this sub]( [param:Vector2 v] )</h3>
<p>Subtracts [page:Vector2 v] from this vector.</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>
<h3>[method:this subVectors]( [param:Vector2 a], [param:Vector2 b] )</h3>
<p>Sets this vector to [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 />
Returns an array [x, y], or copies x and y into the provided [page:Array array].
</p>
<h2>Source</h2>
<p>
[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
</p>
</body>
</html>
|