Vector2.html 7.1 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

45
		<h3>[method:Vector2 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

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

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

60
		<h3>[method:Vector2 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

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

70
		<h3>[method:Vector2 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

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

80
		<h3>[method:Vector2 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

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

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

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

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

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

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

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

121
		<h3>[method:Vector2 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>[method:Boolean equals]( [page:Vector2 v] )</h3>
127 128 129
		<div>
		Checks for strict equality of this vector and *v*.
		</div>
M
Mr.doob 已提交
130

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


137
		<h3>[method:Vector2 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
		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>

146
		<h3>[method:Vector2 clampScalar]([page:Float min], [page:Float max]) [page:Vector2 this]</h3>
147 148 149 150 151 152 153 154
		<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>

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

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

165
		<h3>[method:Vector2 round]()</h3>
166 167 168 169
		<div>
		The components of the vector are rounded towards the nearest integer value.
		</div>

170
		<h3>[method:Vector2 roundToZero]()</h3>
171 172
		<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>

175
		<h3>[method:Vector2 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>

W
WestLangley 已提交
184 185 186 187 188 189 190 191 192 193
		<h3>[method:Vector2 lerpVectors]([page:Vector2 v1], [page:Vector2 v2], [page:Float alpha]) [page:Vector2 this]</h3>
		<div>
		v1 -- [page:Vector2] <br />
		v2 -- [page:Vector2] <br />
		alpha -- [page:Float] between 0 and 1.
		</div>
		<div>
		Sets this vector to be the vector linearly interpolated between *v1* and *v2* with *alpha* factor.
		</div>

194
		<h3>[method:undefined setComponent]([page:Integer index], [page:Float value])</h3>
C
cjshannon 已提交
195
		<div>
196
		index -- 0 or 1 <br />
G
Greg Tatum 已提交
197
		value -- [page:Float]
C
cjshannon 已提交
198 199
		</div>
		<div>
200 201
		if index equals 0 method replaces this.x with value. <br />
		if index equals 1 method replaces this.y with value.
C
cjshannon 已提交
202 203
		</div>

204
		<h3>[method:Vector2 addScalar]([page:Float s]) [page:Vector2 this]</h3>
C
cjshannon 已提交
205
		<div>
G
Greg Tatum 已提交
206
		s -- [page:Float]
C
cjshannon 已提交
207 208
		</div>
		<div>
209
		Add the scalar value s to this vector's x and y values.
C
cjshannon 已提交
210 211
		</div>

212
		<h3>[method:Float getComponent]([page:Integer index])</h3>
C
cjshannon 已提交
213
		<div>
214
		index -- 0 or 1
C
cjshannon 已提交
215 216
		</div>
		<div>
217 218
		if index equals 0 returns the x value. <br />
		if index equals 1 returns the y value.
C
cjshannon 已提交
219 220
		</div>

221
		<h3>[method:Vector2 fromArray]([page:Array array]) [page:Vector2 this]</h3>
C
cjshannon 已提交
222
		<div>
G
Greg Tatum 已提交
223
		array -- [page:Array] of length 2
C
cjshannon 已提交
224 225
		</div>
		<div>
226
		Sets this vector's x value to be array[0] and y value to be array[1].
C
cjshannon 已提交
227 228
		</div>

W
Wandalen 已提交
229 230 231 232
		<h3>[method:Array toArray]( [page:Array array] )</h3>
		<div>
		array -- Optional array to store the vector.
		</div>
G
Greg Tatum 已提交
233 234 235 236
		<div>
		Returns an array [x, y].
		</div>

237
		<h3>[method:Vector2 min]([page:Vector2 v]) [page:Vector2 this]</h3>
G
Greg Tatum 已提交
238 239 240 241 242 243 244
		<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>

245
		<h3>[method:Vector2 max]([page:Vector2 v]) [page:Vector2 this]</h3>
C
cjshannon 已提交
246
		<div>
247
		v -- [page:Vector2]
C
cjshannon 已提交
248 249
		</div>
		<div>
250
		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 已提交
251 252
		</div>

253
		<h3>[method:Vector2 setX]([page:Float x]) [page:Vector2 this]</h3>
C
cjshannon 已提交
254
		<div>
G
Greg Tatum 已提交
255
		x -- [page:Float]
C
cjshannon 已提交
256 257
		</div>
		<div>
258
		replace this vector's x value with x.
C
cjshannon 已提交
259 260
		</div>

261
		<h3>[method:Vector2 setY]([page:Float y]) [page:Vector2 this]</h3>
C
cjshannon 已提交
262
		<div>
G
Greg Tatum 已提交
263
		y -- [page:Float]
C
cjshannon 已提交
264 265
		</div>
		<div>
266
		replace this vector's y value with y.
C
cjshannon 已提交
267 268
		</div>

269 270 271 272 273
		<h2>Source</h2>

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