forked from processing-js/processing-js.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPVector.html
More file actions
164 lines (142 loc) · 5 KB
/
Copy pathPVector.html
File metadata and controls
164 lines (142 loc) · 5 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
---
layout: default
---
<table cellpadding="0" cellspacing="0" border="0" class="ref-item">
<tr class="name-row">
<th scope="row">Name</th>
<td><h3>PVector</h3></td>
</tr>
<tr class="">
<th scope="row">Examples</th>
<td><div class="example"><pre class="">PVector v1, v2;
void setup() {
smooth();
noLoop();
v1 = new PVector(40, 20);
v2 = new PVector(25, 50);
}
void draw() {
ellipse(v1.x, v1.y, 12, 12);
ellipse(v2.x, v2.y, 12, 12);
v2.add(v1);
ellipse(v2.x, v2.y, 24, 24);
}</pre></div></td>
</tr>
<tr class="">
<th scope="row">Description</th>
<td><p>A class to describe a two or three dimensional vector. This datatype stores two or three variables that are commonly used as a position,
velocity, and/or acceleration. Technically, position is a point and velocity and acceleration are vectors, but this is often simplified to consider
all three as vectors. For example, if you consider a rectangle moving across the screen, at any given instant it has a position (the object's location,
expressed as a point.), 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 PVector class. </p>
<p>There are additional methods and other ways to use some of these methods in the <a href="http://processing.googlecode.com/svn-history/r7367/trunk/processing/build/javadoc/core/processing/core/PVector.html">developers reference</a>.</p></td>
</tr>
<tr class="">
<th scope="row">Fields</th>
<td>
<table cellpadding="0" cellspacing="0" border="0">
<tr class="">
<th scope="row"><a href="../reference/PVector_x">x</a></th>
<td>x component of the vector</td>
</tr>
<tr class="">
<th scope="row"><a href="../reference/PVector_y">y</a></th>
<td>y component of the vector</td>
</tr>
<tr class="">
<th scope="row"><a href="../reference/PVector_z">z</a></th>
<td>z component of the vector</td>
</tr>
</table>
</td>
</tr>
<tr class="">
<th scope="row">Methods</th>
<td><table cellpadding="0" cellspacing="0" border="0">
<tr class="">
<th scope="row"><a href="../reference/PVector_get_">get()</a></th>
<td>Gets the x, y, z component of the vector</td>
</tr>
<tr class="">
<th scope="row"><a href="../reference/PVector_set_">set()</a></th>
<td>Sets the x, y, z component of the vector</td>
</tr>
<tr class="">
<th scope="row"><a href="../reference/PVector_mag_">mag()</a></th>
<td>Calculates the magnitude (length) of the vector and returns the result as a float </td>
</tr>
<tr class="">
<th scope="row"><a href="../reference/PVector_add_">add()</a></th>
<td>Adds one vector to another</td>
</tr>
<tr class="">
<th scope="row"><a href="../reference/PVector_sub_">sub()</a></th>
<td> Subtracts one vector from another</td>
</tr>
<tr class="">
<th scope="row"><a href="../reference/PVector_mult_">mult()</a></th>
<td>Multiplies the vector by a scalar</td>
</tr>
<tr class="">
<th scope="row"><a href="../reference/PVector_div_">div()</a></th>
<td>Divides the vector by a scalar</td>
</tr>
<tr class="">
<th scope="row"><a href="../reference/PVector_dist_">dist()</a></th>
<td>Calculate the Euclidean distance between two points</td>
</tr>
<tr class="">
<th scope="row"><a href="../reference/PVector_dot_">dot()</a></th>
<td>Calculates the dot product</td>
</tr>
<tr class="">
<th scope="row"><a href="../reference/PVector_cross_">cross()</a></th>
<td>Calculates the cross product</td>
</tr>
<tr class="">
<th scope="row"><a href="../reference/PVector_normalize_">normalize()</a></th>
<td>Normalizes the vector</td>
</tr>
<tr class="">
<th scope="row"><a href="../reference/PVector_limit_">limit()</a></th>
<td>Limits the magnitude of the vector</td>
</tr>
<tr class="">
<th scope="row"><a href="../reference/PVector_angleBetween_">angleBetween()</a></th>
<td>Calculates the angle between two vectors</td>
</tr>
<tr class="">
<th scope="row"><a href="../reference/PVector_array_">array()</a></th>
<td>Return a representation of the vector as an array</td>
</tr>
</table></td>
</tr>
<tr class="">
<th scope="row"><!--*-->Constructor<!--*--></th>
<td><pre>PVector()</pre><br />
<pre>PVector(<kbd>x</kbd>,<kbd>y</kbd>)</pre><br />
<pre>PVector(<kbd>x</kbd>,<kbd>y</kbd>,<kbd>z</kbd>)</pre></td>
</tr>
<tr class="">
<th scope="row">Parameters</th>
<td><table cellpadding="0" cellspacing="0" border="0">
<tr class="">
<th scope="row">x</th>
<td>float: x component</td>
</tr>
<tr class="">
<th scope="row">y</th>
<td>float: y component</td>
</tr>
<tr class="">
<th scope="row">z</th>
<td>float: z component</td>
</tr>
</table></td>
</tr>
<tr class="">
<th scope="row">Usage</th>
<td>Web & Application</td>
</tr>
</table>