-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathvector.html
More file actions
139 lines (129 loc) · 8.45 KB
/
Copy pathvector.html
File metadata and controls
139 lines (129 loc) · 8.45 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
<!-- InstanceBegin template="/Templates/template.dwt" codeOutsideHTMLIsLocked="false" --><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>vector</title>
<!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="head" -->
<link href="VisualRef.css" rel="stylesheet" type="text/css" />
<!-- InstanceEndEditable -->
<link href="VisualRef.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table width="230" height="30" border="0">
<tr>
<td width="66"><a name="top" id="top"></a><a href="index.html"><strong>Home</strong></a></td>
<td width="154"><span class="Normal"><a href="primitives.html"><strong>Pictures</strong></a> of 3D objects</span></td>
</tr>
</table>
<table width="438" height="30" border="0">
<tr>
<td width="151"><select id="menu1" onchange="jumpMenu(this)">
</select></td>
<td width="163"><select id="menu2" onchange="jumpMenu(this)">
</select></td>
<td width="110"><select id="menu3" onchange="jumpMenu(this)">
</select></td>
</tr>
</table>
<table width="454" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutDefaultTable-->
<tr>
<td width="454" rowspan="2" valign="top"><!-- InstanceBeginEditable name="content" -->
<h1 class="Heading-1"> <font color="#0000a0">The vector object</font></h1>
<p class="Normal"> The vector object is not a displayable object but is
a powerful aid to 3D computations. Its properties are similar to
vectors used in science and engineering.</p>
<p class="program">vec(x,y,z)</p>
<p class="Normal"> This creates a 3D vector object with the given components x, y, and z.</p>
<p class="Normal"> Vectors can be added or subtracted from each other, or multiplied by an
ordinary number. For example,</p>
<p class="program">var v1 = vec(1,2,3)<br />
var v2 = vec(10,20,30)<br />
v1+v2 # same as vec( 1, 22, 33)<br />
20*v1 # same as vec(20, 40, 60)</p>
<p class="Normal"> You can refer to individual components of a vector:</p>
<p class="Normal"> <span class="attribute">v2.x</span> is 10, <span
class="attribute">v2.y</span> is 20, <span class="attribute">v2.z</span> is 30 </p>
<p class="Normal"> It is okay to make a vector from a vector: <span
class="attribute">vec(v2)</span> is still <span class="attribute">vec(10,20,30)</span>. This is a convenient way to make a separate copy of a vector.</p>
<p class="Normal"><strong><font color="#0000a0">Vector functions</font></strong></p>
<p class="Normal">The following functions are available for working with vectors: </p>
<p class="Normal"><strong>mag(A) = A.mag</strong> = |A|, the magnitude of a vector<br />
<br />
<strong>mag2(A) = A.mag2</strong> = |A|*|A|, the vector's magnitude squared<br />
<br />
<strong>norm(A) = A.norm()</strong> = A/|A|, a unit vector in the direction of the vector<br />
<br />
<strong>hat(A) = A.hat</strong> =
A/|A|, a unit vector in the direction of the vector; an alternative to A.norm(), based on the fact that unit vectors are customarily written in the form <strong>ĉ</strong>, with a "hat" over the vector<br />
<br />
<strong>dot(A,B) = A.dot(B)</strong> = A dot B, the scalar dot product between two vectors<br />
<br />
<strong>cross(A,B) = A.cross(B</strong>), the vector cross product between two vectors<br />
<br />
<strong>diff_angle(A,B) = A.diff_angle(B)</strong>, the angle between two vectors, in radians<br />
<br />
<strong>proj(A,B) = A.proj(B) = dot(A,norm(B))*norm(B)</strong>, the vector projection of A along B<br />
<br />
<strong>comp(A,B) = A.comp(B) = dot(A,norm(B))</strong>, the scalar projection of A along B<br />
<br />
<strong>A.equals(B)</strong> is True if <strong>A</strong> and <strong>B</strong> have the same components (which means that they have the same magnitude and the same direction) <br />
<br />
<strong>vec.random()</strong> produces a vector each of whose components are random numbers in the range -1 to +1<br />
<br />
Some examples:</p>
<p class="program"> mag(A) # calculates length of A <br />
mag(vec(1,1,1)) # = sqrt(3) = 1.732...<br />
mag2(vec(1,1,1)) # = 3; magnitude
squared</p>
<p class="Normal">It is possible to reset the magnitude or the
magnitude squared of a vector:</p>
<p class="program"> v2.mag = 5 # sets magnitude to 5;<br />
# no change in direction<br />
v2.mag2 = 2.7 # sets squared magnitude<br />
# of v2 to
2.7</p>
<p class="Normal">You can reset the magnitude to 1 with norm():</p>
<p class="program">norm(A) # A/|A|, normalized; magnitude 1<br />
norm(vec(1,1,1)) # vec(1,1,1)/sqrt(3)</p>
<p class="Normal">You can also write <span class="attribute">v1.norm()</span><span
class="attribute"></span> or <span class="attribute">v1.hat</span>. For convenience, <span class="attribute">norm(vec(0,0,0))</span> is calculated to be <span class="attribute">vec(0,0,0)</span>. <span class="attribute"></span> </p>
<p class="Normal">You can change the direction of a vector without changing its magnitude:</p>
<p class="program"> v2.hat = v1 # changes the direction of v2<br />
# but not its magnitude<br />
</p>
<p class="Normal">To calculate the angle between two vectors (the "difference"
of the angles of the two vectors):</p>
<p class="program">ang = v1.diff_angle(v2)</p>
<p class="Normal"> You can also write <span class="attribute">v1.diff_angle(v2)</span><span
class="attribute"></span>. For convenience, if either of the vectors has zero
magnitude, the difference of the angles is calculated to be zero<span class="attribute"></span>.</p>
<p class="Normal"><strong>cross(A,B)</strong> or <strong>A.cross(B)</strong> gives the cross product of two vectors, a vector perpendicular to the plane defined by <strong>A</strong> and <strong>B</strong>,
in a direction defined by the right-hand rule: if the fingers of the right
hand bend from <strong>A</strong> toward <strong>B</strong>, the thumb points in the direction
of the cross product. The magnitude of this vector is equal to <strong>mag(A)*mag(B)*sin(A.diff_angle(B))</strong>.</p>
<p class="Normal"><strong>dot(A,B)</strong> or <strong>A.dot(B) </strong>gives the dot product of two vectors,
which is an ordinary number equal to <strong>mag(A)*mag(B)*cos(A.diff_angle(B))</strong>. If the
two vectors are normalized, the dot product gives the cosine of the angle
between the vectors, which is often useful. </p>
<p class="Normal"><font color="#0000a0"><strong>Rotating a vector</strong></font></p>
<p class="Normal"> There is a function for rotating a vector:<font color="#0000a0"></font></p>
<p class="program"> v2 = rotate(v1, angle=a, axis=vec(x,y,z))</p>
<p class="Normal">The angle must be in radians. The default axis is
(0,0,1), for a rotation counterclockwise in the xy plane around the z axis. There
is no origin for rotating a vector. You can also write <span class="attribute">v2
= v1.rotate(angle=theta, axis=vec(1,1,1))</span>. There is also a <a href="rotation.html">rotate capability for
objects</a>.</p>
<p class="Normal">The JavaScript versions are v2 = rotate(v1, {angle:a, axis=vec(x,y,z}) and v2 = v1.rotate({angle:a, axis=vec(x,y,z}).</p>
<p class="Normal">There are functions for converting between degrees
and radians, where there are 2*pi radians in 360 degrees: </p>
<p class="program">radians(360) is equivalent to 2*pi<br />
degrees(2*pi) is equivalent to 360</p>
<p class="Normal"></p>
<!-- InstanceEndEditable --></td>
</tr>
</table>
<p><a href="#top"><strong>Top of page</strong></a></p>
</body>
<script type="text/javascript" language="javascript" src="navigation.js"></script>
<!-- InstanceEnd --></html>