forked from jdf/processing-py-site
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPVector.xml
More file actions
188 lines (154 loc) · 5.61 KB
/
PVector.xml
File metadata and controls
188 lines (154 loc) · 5.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<root>
<name>PVector</name>
<category>Math</category>
<subcategory>PVector</subcategory>
<type></type>
<example>
<image />
<code><![CDATA[
v1 = PVector(40, 20)
v2 = PVector(25, 50)
ellipse(v1.x, v1.y, 12, 12)
ellipse(v2.x, v2.y, 12, 12)
v2.add(v1) # v2 += v1
ellipse(v2.x, v2.y, 24, 24)
]]></code>
</example>
<description><![CDATA[
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 />
<br />
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 />
<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.
]]></description>
<syntax>
v = PVector(x, y)
v = PVector(x, y, z)
</syntax>
<parameter>
<label>x</label>
<description><![CDATA[int: x component of the PVector]]></description>
</parameter>
<parameter>
<label>y</label>
<description><![CDATA[int: y component of the PVector]]></description>
</parameter>
<parameter>
<label>z</label>
<description><![CDATA[int: z component of the PVector]]></description>
</parameter>
<method>
<label>set()</label>
<description> Set the components of the vector</description>
<ref>PVector_set</ref>
</method>
<method>
<label>random2D()</label>
<description> Make a new 2D unit vector with a random direction.</description>
<ref>PVector_random2D</ref>
</method>
<method>
<label>random3D()</label>
<description> Make a new 3D unit vector with a random direction.</description>
<ref>PVector_random3D</ref>
</method>
<method>
<label>fromAngle()</label>
<description> Make a new 2D unit vector from an angle</description>
<ref>PVector_fromAngle</ref>
</method>
<method>
<label>fromAngle()</label>
<description> Make a new 2D unit vector from an angle</description>
<ref>PVector_fromAngle</ref>
</method>
<method>
<label>copy()</label>
<description> Get a copy of the vector</description>
<ref>PVector_copy</ref>
</method>
<method>
<label>mag()</label>
<description> Calculate the magnitude of the vector</description>
<ref>PVector_mag</ref>
</method><method>
<label>magSq()</label>
<description> Calculate the magnitude of the vector, squared</description>
<ref>PVector_magSq</ref>
</method>
<method>
<label>add()</label>
<description> Adds x, y, and z components to a vector, one vector to another, or two independent vectors</description>
<ref>PVector_add</ref>
</method>
<method>
<label>sub()</label>
<description> Subtract x, y, and z components from a vector, one vector from another, or two independent vectors</description>
<ref>PVector_sub</ref>
</method>
<method>
<label>mult()</label>
<description> Multiply a vector by a scalar</description>
<ref>PVector_mult</ref>
</method>
<method>
<label>div()</label>
<description> Divide a vector by a scalar</description>
<ref>PVector_div</ref>
</method>
<method>
<label>dist()</label>
<description> Calculate the distance between two points</description>
<ref>PVector_dist</ref>
</method>
<method>
<label>dot()</label>
<description> Calculate the dot product of two vectors</description>
<ref>PVector_dot</ref>
</method>
<method>
<label>cross()</label>
<description> Calculate and return the cross product</description>
<ref>PVector_cross</ref>
</method>
<method>
<label>normalize()</label>
<description> Normalize the vector to a length of 1</description>
<ref>PVector_normalize</ref>
</method>
<method>
<label>limit()</label>
<description> Limit the magnitude of the vector</description>
<ref>PVector_limit</ref>
</method>
<method>
<label>setMag()</label>
<description> Set the magnitude of the vector</description>
<ref>PVector_setMag</ref>
</method>
<method>
<label>heading()</label>
<description> Calculate the angle of rotation for this vector</description>
<ref>PVector_heading</ref>
</method>
<method>
<label>rotate()</label>
<description> Rotate the vector by an angle (2D only)</description>
<ref>PVector_rotate</ref>
</method>
<method>
<label>lerp()</label>
<description> Linear interpolate the vector to another vector</description>
<ref>PVector_lerp</ref>
</method>
<method>
<label>angleBetween()</label>
<description> Calculate and return the angle between two vectors</description>
<ref>PVector_angleBetween</ref>
</method>
<method>
<label>array()</label>
<description> Return a representation of the vector as a float array</description>
<ref>PVector_array</ref>
</method>
</root>