Vector2.html 5.2 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>.[page:Float x]</h3>
M
Mr.doob 已提交
39

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


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

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

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

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

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

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

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

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

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

86 87 88 89
		<h3>.negate() [page:Vector2]</h3>
		<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

106 107 108 109
		<h3>.normalize() [page:Vector2]</h3>
		<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

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

126 127 128 129
		<h3>.equals( [page:Vector2 v] ) [page:Vector2]</h3>
		<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>


137
		<h3>.clamp([page:todo min], [page:todo max]) [page: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
		If this vector's x or y value is greater than the max vector's x or y value, it is replaced by that 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 that value.
C
cjshannon 已提交
144 145
		</div>

146
		<h3>.toArray() [page:Array]</h3>
C
cjshannon 已提交
147
		<div>
148
		Returns an array [x, y].
C
cjshannon 已提交
149 150
		</div>

151
		<h3>.lerp([page:todo v], [page:todo alpha]) [page:this]</h3>
C
cjshannon 已提交
152
		<div>
153 154
		v -- [page:Vector2] <br />
		alpha -- [page:Float] between 0 and 1;
C
cjshannon 已提交
155 156
		</div>
		<div>
157
		Linear interpolation between this vector and v, where alpha is the percent along the line.
C
cjshannon 已提交
158 159
		</div>

160
		<h3>.setComponent([page:todo index], [page:todo value]) [page:undefined]</h3>
C
cjshannon 已提交
161
		<div>
162 163
		index -- 0 or 1 <br />
		value -- [page:todo Float]
C
cjshannon 已提交
164 165
		</div>
		<div>
166 167
		if index equals 0 method replaces this.x with value. <br />
		if index equals 1 method replaces this.y with value.
C
cjshannon 已提交
168 169
		</div>

170
		<h3>.min([page:todo v]) [page:this]</h3>
C
cjshannon 已提交
171
		<div>
172
		v -- [page:Vector2]
C
cjshannon 已提交
173 174
		</div>
		<div>
175
		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.
C
cjshannon 已提交
176 177
		</div>

178
		<h3>.addScalar([page:todo s]) [page:this]</h3>
C
cjshannon 已提交
179
		<div>
180
		s -- [page:todo Float]
C
cjshannon 已提交
181 182
		</div>
		<div>
183
		Add the scalar value s to this vector's x and y values.
C
cjshannon 已提交
184 185
		</div>

186
		<h3>.getComponent([page:todo index]) [page:todo Float]</h3>
C
cjshannon 已提交
187
		<div>
188
		index -- 0 or 1
C
cjshannon 已提交
189 190
		</div>
		<div>
191 192
		if index equals 0 returns the x value. <br />
		if index equals 1 returns the y value.
C
cjshannon 已提交
193 194
		</div>

195
		<h3>.fromArray([page:todo array]) [page:todo this]</h3>
C
cjshannon 已提交
196
		<div>
197
		array -- [page:todo Array] of length 2
C
cjshannon 已提交
198 199
		</div>
		<div>
200
		Sets this vector's x value to be array[0] and y value to be array[1].
C
cjshannon 已提交
201 202
		</div>

203
		<h3>.max([page:todo v]) [page:todo this]</h3>
C
cjshannon 已提交
204
		<div>
205
		v -- [page:Vector2]
C
cjshannon 已提交
206 207
		</div>
		<div>
208
		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 已提交
209 210
		</div>

211
		<h3>.setX([page:todo x]) [page:todo this]</h3>
C
cjshannon 已提交
212
		<div>
213
		x -- [page:todo Float]
C
cjshannon 已提交
214 215
		</div>
		<div>
216
		replace this vector's x value with x.
C
cjshannon 已提交
217 218
		</div>

219
		<h3>.setY([page:todo y]) [page:todo this]</h3>
C
cjshannon 已提交
220
		<div>
221
		y -- [page:todo Float]
C
cjshannon 已提交
222 223
		</div>
		<div>
224
		replace this vector's y value with y.
C
cjshannon 已提交
225 226
		</div>

227 228 229 230 231
		<h2>Source</h2>

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