You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit c6582a3
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: Reference/api_en/PVector.xml
+140-9Lines changed: 140 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -16,21 +16,21 @@ v2 = PVector(25, 50)
16
16
17
17
ellipse(v1.x, v1.y, 12, 12)
18
18
ellipse(v2.x, v2.y, 12, 12)
19
-
v2.add(v1)
19
+
v2.add(v1) # v2 += v1
20
20
ellipse(v2.x, v2.y, 24, 24)
21
21
]]></code>
22
22
</example>
23
23
24
-
25
24
<description><![CDATA[
26
25
A class to describe a two or three dimensional vector, specifically a Euclidean (also known as geometric) vector. A vector is an entity that has both magnitude and direction. The datatype, however, stores the components of the vector (x,y for 2D, and x,y,z for 3D). The magnitude and direction can be accessed via the methods <b>mag()</b> and <b>heading()</b>.<br />
27
26
<br />
28
-
In many of the Processing examples, you will see <b>PVector</b> used to describe a position, velocity, or acceleration. For example, if you consider a rectangle moving across the screen, at any given instant it has a position (a vector that points from the origin to its location), a velocity (the rate at which the object's position changes per time unit, expressed as a vector), and acceleration (the rate at which the object's velocity changes per time unit, expressed as a vector). Since vectors represent groupings of values, we cannot simply use traditional addition/multiplication/etc. Instead, we'll need to do some "vector" math, which is made easy by the methods inside the <b>PVector</b> class.
27
+
In many of the Processing examples, you will see <b>PVector</b> used to describe a position, velocity, or acceleration. For example, if you consider a rectangle moving across the screen, at any given instant it has a position (a vector that points from the origin to its location), a velocity (the rate at which the object's position changes per time unit, expressed as a vector), and acceleration (the rate at which the object's velocity changes per time unit, expressed as a vector).<br />
28
+
<br />Since vectors represent groupings of values, we'll need to do some "vector" math, which is made easy by the methods inside the <b>PVector</b> class, or, in Python Mode, in some cases the traditional mathematical operators have been "overloaded" to work with PVectors: "+" adds vectors, "-" subtracts vectors, "*" does scalar multiplication, and "/" does scalar division. The related augmented assigment operators, "+=", "-=", "*=", and "/=", also work.
29
29
]]></description>
30
30
31
31
<syntax>
32
-
var = PVector(x, y)
33
-
var = PVector(x, y, z)
32
+
v = PVector(x, y)
33
+
v = PVector(x, y, z)
34
34
</syntax>
35
35
36
36
<parameter>
@@ -48,10 +48,141 @@ In many of the Processing examples, you will see <b>PVector</b> used to describe
48
48
<description><![CDATA[int: z component of the PVector]]></description>
49
49
</parameter>
50
50
51
-
<parameter>
52
-
<label>var</label>
53
-
<description><![CDATA[variable which refers to the PVector]]></description>
54
-
</parameter>
51
+
<method>
52
+
<label>set()</label>
53
+
<description> Set the components of the vector</description>
54
+
<ref>PVector_set</ref>
55
+
</method>
56
+
57
+
<method>
58
+
<label>random2D()</label>
59
+
<description> Make a new 2D unit vector with a random direction.</description>
60
+
<ref>PVector_random2D</ref>
61
+
</method>
62
+
63
+
<method>
64
+
<label>random3D()</label>
65
+
<description> Make a new 3D unit vector with a random direction.</description>
66
+
<ref>PVector_random3D</ref>
67
+
</method>
68
+
69
+
<method>
70
+
<label>fromAngle()</label>
71
+
<description> Make a new 2D unit vector from an angle</description>
72
+
<ref>PVector_fromAngle</ref>
73
+
</method>
74
+
75
+
<method>
76
+
<label>fromAngle()</label>
77
+
<description> Make a new 2D unit vector from an angle</description>
78
+
<ref>PVector_fromAngle</ref>
79
+
</method>
80
+
81
+
<method>
82
+
<label>copy()</label>
83
+
<description> Get a copy of the vector</description>
84
+
<ref>PVector_copy</ref>
85
+
</method>
86
+
87
+
<method>
88
+
<label>mag()</label>
89
+
<description> Calculate the magnitude of the vector</description>
90
+
<ref>PVector_mag</ref>
91
+
92
+
</method><method>
93
+
<label>magSq()</label>
94
+
<description> Calculate the magnitude of the vector, squared</description>
95
+
<ref>PVector_magSq</ref>
96
+
</method>
97
+
98
+
<method>
99
+
<label>add()</label>
100
+
<description> Adds x, y, and z components to a vector, one vector to another, or two independent vectors</description>
101
+
<ref>PVector_add</ref>
102
+
</method>
103
+
104
+
<method>
105
+
<label>sub()</label>
106
+
<description> Subtract x, y, and z components from a vector, one vector from another, or two independent vectors</description>
107
+
<ref>PVector_sub</ref>
108
+
</method>
109
+
110
+
<method>
111
+
<label>mult()</label>
112
+
<description> Multiply a vector by a scalar</description>
113
+
<ref>PVector_mult</ref>
114
+
</method>
115
+
116
+
<method>
117
+
<label>div()</label>
118
+
<description> Divide a vector by a scalar</description>
119
+
<ref>PVector_div</ref>
120
+
</method>
121
+
122
+
<method>
123
+
<label>dist()</label>
124
+
<description> Calculate the distance between two points</description>
125
+
<ref>PVector_dist</ref>
126
+
</method>
127
+
128
+
<method>
129
+
<label>dot()</label>
130
+
<description> Calculate the dot product of two vectors</description>
131
+
<ref>PVector_dot</ref>
132
+
</method>
133
+
134
+
<method>
135
+
<label>cross()</label>
136
+
<description> Calculate and return the cross product</description>
137
+
<ref>PVector_cross</ref>
138
+
</method>
139
+
140
+
<method>
141
+
<label>normalize()</label>
142
+
<description> Normalize the vector to a length of 1</description>
143
+
<ref>PVector_normalize</ref>
144
+
</method>
145
+
146
+
<method>
147
+
<label>limit()</label>
148
+
<description> Limit the magnitude of the vector</description>
149
+
<ref>PVector_limit</ref>
150
+
</method>
151
+
152
+
<method>
153
+
<label>setMag()</label>
154
+
<description> Set the magnitude of the vector</description>
155
+
<ref>PVector_setMag</ref>
156
+
</method>
157
+
158
+
<method>
159
+
<label>heading()</label>
160
+
<description> Calculate the angle of rotation for this vector</description>
161
+
<ref>PVector_heading</ref>
162
+
</method>
163
+
164
+
<method>
165
+
<label>rotate()</label>
166
+
<description> Rotate the vector by an angle (2D only)</description>
167
+
<ref>PVector_rotate</ref>
168
+
</method>
169
+
170
+
<method>
171
+
<label>lerp()</label>
172
+
<description> Linear interpolate the vector to another vector</description>
173
+
<ref>PVector_lerp</ref>
174
+
</method>
175
+
176
+
<method>
177
+
<label>angleBetween()</label>
178
+
<description> Calculate and return the angle between two vectors</description>
179
+
<ref>PVector_angleBetween</ref>
180
+
</method>
55
181
182
+
<method>
183
+
<label>array()</label>
184
+
<description> Return a representation of the vector as a float array</description>
0 commit comments