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

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
		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.
C
cjshannon 已提交
144 145
		</div>

G
Greg Tatum 已提交
146
		<h3>.lerp([page:Vector2 v], [page:Float alpha]) [page:Vector2 this]</h3>
C
cjshannon 已提交
147
		<div>
148 149
		v -- [page:Vector2] <br />
		alpha -- [page:Float] between 0 and 1;
C
cjshannon 已提交
150 151
		</div>
		<div>
152
		Linear interpolation between this vector and v, where alpha is the percent along the line.
C
cjshannon 已提交
153 154
		</div>

G
Greg Tatum 已提交
155
		<h3>.setComponent([page:Integer index], [page:Float value]) [page:undefined]</h3>
C
cjshannon 已提交
156
		<div>
157
		index -- 0 or 1 <br />
G
Greg Tatum 已提交
158
		value -- [page:Float]
C
cjshannon 已提交
159 160
		</div>
		<div>
161 162
		if index equals 0 method replaces this.x with value. <br />
		if index equals 1 method replaces this.y with value.
C
cjshannon 已提交
163 164
		</div>

G
Greg Tatum 已提交
165
		<h3>.addScalar([page:Float s]) [page:Vector2 this]</h3>
C
cjshannon 已提交
166
		<div>
G
Greg Tatum 已提交
167
		s -- [page:Float]
C
cjshannon 已提交
168 169
		</div>
		<div>
170
		Add the scalar value s to this vector's x and y values.
C
cjshannon 已提交
171 172
		</div>

G
Greg Tatum 已提交
173
		<h3>.getComponent([page:Integer index]) [page:Float]</h3>
C
cjshannon 已提交
174
		<div>
175
		index -- 0 or 1
C
cjshannon 已提交
176 177
		</div>
		<div>
178 179
		if index equals 0 returns the x value. <br />
		if index equals 1 returns the y value.
C
cjshannon 已提交
180 181
		</div>

G
Greg Tatum 已提交
182
		<h3>.fromArray([page:Array array]) [page:Vector2 this]</h3>
C
cjshannon 已提交
183
		<div>
G
Greg Tatum 已提交
184
		array -- [page:Array] of length 2
C
cjshannon 已提交
185 186
		</div>
		<div>
187
		Sets this vector's x value to be array[0] and y value to be array[1].
C
cjshannon 已提交
188 189
		</div>

G
Greg Tatum 已提交
190 191 192 193 194 195 196 197 198 199 200 201 202 203
		<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 已提交
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>

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

G
Greg Tatum 已提交
219
		<h3>.setY([page:Float y]) [page:Vector2 this]</h3>
C
cjshannon 已提交
220
		<div>
G
Greg Tatum 已提交
221
		y -- [page: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>