Vector2.html 6.4 KB
Newer Older
1 2 3
<!DOCTYPE html>
<html lang="en">
	<head>
4
		<meta charset="utf-8" />
5 6 7 8 9 10
		<script src="../../list.js"></script>
		<script src="../../page.js"></script>
		<link type="text/css" rel="stylesheet" href="../../page.css" />
	</head>
	<body>
		<h1>[name]</h1>
M
Mr.doob 已提交
11

M
Mr.doob 已提交
12
		<div class="desc">2D vector.</div>
M
Mr.doob 已提交
13

14
		<h2>Example</h2>
M
Mr.doob 已提交
15

16 17
		<code>var a = new THREE.Vector2( 0, 1 );
		var b = new THREE.Vector2( 1, 0 );
M
Mr.doob 已提交
18

19 20
		var d = a.distanceTo( b );
		</code>
M
Mr.doob 已提交
21 22


23
		<h2>Constructor</h2>
M
Mr.doob 已提交
24

C
cjshannon 已提交
25

26
		<h3>[name]( [page:Float x], [page:Float y] )</h3>
C
cjshannon 已提交
27
		<div>
28 29
		x -- [page:Float] representing the x value of the vector <br />
		y -- [page:Float] representing the y value of the vector
C
cjshannon 已提交
30 31
		</div>
		<div>
32
		A vector in 2 dimensional space
C
cjshannon 已提交
33
		</div>
M
Mr.doob 已提交
34 35


36
		<h2>Properties</h2>
M
Mr.doob 已提交
37

38
		<h3>[property:Float x]</h3>
M
Mr.doob 已提交
39

40
		<h3>[property:Float y]</h3>
M
Mr.doob 已提交
41 42


43
		<h2>Methods</h2>
M
Mr.doob 已提交
44

G
Greg Tatum 已提交
45
		<h3>.set( [page:Float x], [page:Float y] ) [page:Vector2 this]</h3>
46 47 48
		<div>
		Sets value of this vector.
		</div>
M
Mr.doob 已提交
49

G
Greg Tatum 已提交
50
		<h3>.copy( [page:Vector2 v] ) [page:Vector2 this]</h3>
51 52 53
		<div>
		Copies value of *v* to this vector.
		</div>
M
Mr.doob 已提交
54

G
Greg Tatum 已提交
55
		<h3>.add( [page:Vector2 v] ) [page:Vector2 this]</h3>
56
		<div>
57
		Adds *v* to this vector.
58
		</div>
M
Mr.doob 已提交
59

G
Greg Tatum 已提交
60
		<h3>.addVectors( [page:Vector2 a], [page:Vector2 b] ) [page:Vector2 this]</h3>
61
		<div>
62
		Sets this vector to *a + b*.
63
		</div>
M
Mr.doob 已提交
64

G
Greg Tatum 已提交
65
		<h3>.sub( [page:Vector2 v] ) [page:Vector2 this]</h3>
66
		<div>
67
		Subtracts *v* from this vector.
68
		</div>
M
Mr.doob 已提交
69

G
Greg Tatum 已提交
70
		<h3>.subVectors( [page:Vector2 a], [page:Vector2 b] ) [page:Vector2 this]</h3>
71
		<div>
72
		Sets this vector to *a - b*.
73
		</div>
M
Mr.doob 已提交
74

G
Greg Tatum 已提交
75
		<h3>.multiplyScalar( [page:Float s] ) [page:Vector2 this]</h3>
76 77 78
		<div>
		Multiplies this vector by scalar *s*.
		</div>
M
Mr.doob 已提交
79

G
Greg Tatum 已提交
80
		<h3>.divideScalar( [page:Float s] ) [page:Vector2 this]</h3>
81 82 83 84
		<div>
		Divides this vector by scalar *s*.<br />
		Set vector to *( 0, 0 )* if *s == 0*.
		</div>
M
Mr.doob 已提交
85

G
Greg Tatum 已提交
86
		<h3>.negate() [page:Vector2 this]</h3>
87 88 89
		<div>
		Inverts this vector.
		</div>
M
Mr.doob 已提交
90

91 92 93 94
		<h3>.dot( [page:Vector2 v] ) [page:Float]</h3>
		<div>
		Computes dot product of this vector and *v*.
		</div>
M
Mr.doob 已提交
95

96 97 98 99
		<h3>.lengthSq() [page:Float]</h3>
		<div>
		Computes squared length of this vector.
		</div>
M
Mr.doob 已提交
100

101 102 103 104
		<h3>.length() [page:Float]</h3>
		<div>
		Computes length of this vector.
		</div>
M
Mr.doob 已提交
105

G
Greg Tatum 已提交
106
		<h3>.normalize() [page:Vector2 this]</h3>
107 108 109
		<div>
		Normalizes this vector.
		</div>
M
Mr.doob 已提交
110

111 112 113 114
		<h3>.distanceTo( [page:Vector2 v] ) [page:Float]</h3>
		<div>
		Computes distance of this vector to *v*.
		</div>
M
Mr.doob 已提交
115

116 117 118 119
		<h3>.distanceToSquared( [page:Vector2 v] ) [page:Float]</h3>
		<div>
		Computes squared distance of this vector to *v*.
		</div>
M
Mr.doob 已提交
120

G
Greg Tatum 已提交
121
		<h3>.setLength( [page:Float l] ) [page:Vector2 this]</h3>
122 123 124
		<div>
		Normalizes this vector and multiplies it by *l*.
		</div>
M
Mr.doob 已提交
125

126
		<h3>.equals( [page:Vector2 v] ) [page:Boolean]</h3>
127 128 129
		<div>
		Checks for strict equality of this vector and *v*.
		</div>
M
Mr.doob 已提交
130

131 132 133 134 135 136
		<h3>.clone() [page:Vector2]</h3>
		<div>
		Clones this vector.
		</div>


G
Greg Tatum 已提交
137
		<h3>.clamp([page:Vector2 min], [page:Vector2 max]) [page:Vector2 this]</h3>
C
cjshannon 已提交
138
		<div>
139 140
		min -- [page:Vector2] containing the min x and y values in the desired range <br />
		max -- [page:Vector2] containing the max x and y values in the desired range
C
cjshannon 已提交
141 142
		</div>
		<div>
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
		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 />	If this vector's x or y value is less than the min vector's x or y value, it is replace by the corresponding value.
		</div>

		<h3>.clampScalar([page:Float min], [page:Float max]) [page:Vector2 this]</h3>
		<div>
		min -- [page:Float] the minimum value the components will be clamped to <br />
		max -- [page:Float] the maximum value the components will be clamped to
		</div>
		<div>
		If this vector's x or y values are greater than the max value, they are replaced by the max value. <br />  If this vector's x or y values are less than the min value, they are replace by the min value.
		</div>

		<h3>.floor() [page:Vector2]</h3>
		<div>
		The components of the vector are rounded downwards (towards negative infinity) to an integer value.
		</div>

		<h3>.ceil() [page:Vector2]</h3>
		<div>
		The components of the vector are rounded upwards (towards positive infinity) to an integer value.
		</div>

		<h3>.round() [page:Vector2]</h3>
		<div>
		The components of the vector are rounded towards the nearest integer value.
		</div>

		<h3>.roundToZero() [page:Vector2]</h3>
		<div>
		The components of the vector are rounded towards zero (up if negative, down if positive) to an integer value.
C
cjshannon 已提交
173 174
		</div>

G
Greg Tatum 已提交
175
		<h3>.lerp([page:Vector2 v], [page:Float alpha]) [page:Vector2 this]</h3>
C
cjshannon 已提交
176
		<div>
177 178
		v -- [page:Vector2] <br />
		alpha -- [page:Float] between 0 and 1;
C
cjshannon 已提交
179 180
		</div>
		<div>
181
		Linear interpolation between this vector and v, where alpha is the percent along the line.
C
cjshannon 已提交
182 183
		</div>

G
Greg Tatum 已提交
184
		<h3>.setComponent([page:Integer index], [page:Float value]) [page:undefined]</h3>
C
cjshannon 已提交
185
		<div>
186
		index -- 0 or 1 <br />
G
Greg Tatum 已提交
187
		value -- [page:Float]
C
cjshannon 已提交
188 189
		</div>
		<div>
190 191
		if index equals 0 method replaces this.x with value. <br />
		if index equals 1 method replaces this.y with value.
C
cjshannon 已提交
192 193
		</div>

G
Greg Tatum 已提交
194
		<h3>.addScalar([page:Float s]) [page:Vector2 this]</h3>
C
cjshannon 已提交
195
		<div>
G
Greg Tatum 已提交
196
		s -- [page:Float]
C
cjshannon 已提交
197 198
		</div>
		<div>
199
		Add the scalar value s to this vector's x and y values.
C
cjshannon 已提交
200 201
		</div>

G
Greg Tatum 已提交
202
		<h3>.getComponent([page:Integer index]) [page:Float]</h3>
C
cjshannon 已提交
203
		<div>
204
		index -- 0 or 1
C
cjshannon 已提交
205 206
		</div>
		<div>
207 208
		if index equals 0 returns the x value. <br />
		if index equals 1 returns the y value.
C
cjshannon 已提交
209 210
		</div>

G
Greg Tatum 已提交
211
		<h3>.fromArray([page:Array array]) [page:Vector2 this]</h3>
C
cjshannon 已提交
212
		<div>
G
Greg Tatum 已提交
213
		array -- [page:Array] of length 2
C
cjshannon 已提交
214 215
		</div>
		<div>
216
		Sets this vector's x value to be array[0] and y value to be array[1].
C
cjshannon 已提交
217 218
		</div>

G
Greg Tatum 已提交
219 220 221 222 223 224 225 226 227 228 229 230 231 232
		<h3>.toArray() [page:Array]</h3>
		<div>
		Returns an array [x, y].
		</div>

		<h3>.min([page:Vector2 v]) [page:Vector2 this]</h3>
		<div>
		v -- [page:Vector2]
		</div>
		<div>
		If this vector's x or y value is less than v's x or y value, replace that value with the corresponding min value.
		</div>

		<h3>.max([page:Vector2 v]) [page:Vector2 this]</h3>
C
cjshannon 已提交
233
		<div>
234
		v -- [page:Vector2]
C
cjshannon 已提交
235 236
		</div>
		<div>
237
		If this vector's x or y value is greater than v's x or y value, replace that value with the corresponding max value.
C
cjshannon 已提交
238 239
		</div>

G
Greg Tatum 已提交
240
		<h3>.setX([page:Float x]) [page:Vector2 this]</h3>
C
cjshannon 已提交
241
		<div>
G
Greg Tatum 已提交
242
		x -- [page:Float]
C
cjshannon 已提交
243 244
		</div>
		<div>
245
		replace this vector's x value with x.
C
cjshannon 已提交
246 247
		</div>

G
Greg Tatum 已提交
248
		<h3>.setY([page:Float y]) [page:Vector2 this]</h3>
C
cjshannon 已提交
249
		<div>
G
Greg Tatum 已提交
250
		y -- [page:Float]
C
cjshannon 已提交
251 252
		</div>
		<div>
253
		replace this vector's y value with y.
C
cjshannon 已提交
254 255
		</div>

256 257 258 259 260
		<h2>Source</h2>

		[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
	</body>
</html>