-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvector_math.html
More file actions
79 lines (68 loc) · 1.9 KB
/
vector_math.html
File metadata and controls
79 lines (68 loc) · 1.9 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
<!doctype html />
<html>
<head>
<script src="vector.js" type="text/javascript"></script>
<title>Vector Math</title>
</head>
<body onload="main();">
<table>
<tr valign="top">
<td>
<textarea id="output" rows=50 cols=50></textarea>
</td>
<td>
<a href="index.html">Home</a>
<h1>Vector Math</h1>
<p>New Features</p>
<ul>
<li>Vector class</li>
</ul>
</td>
</tr>
</table>
<script type="text/javascript">
var output = document.getElementById("output");
function writeOut(str)
{
output.value += str + "\n";
}
function writeVal(vari, valu)
{
writeOut(vari + " = " + valu);
}
function main()
{
var u = new Vector(1, 2);
var v = new Vector(10, 20);
writeVal("u", u.toString());
writeVal("v", v.toString());
// addition
var w = u.add(v);
writeOut("Vector Addition");
writeVal("u+v", w.toString());
// subtraction
w = u.sub(v);
writeOut("Vector Substraction");
writeVal("u-v", w.toString());
// magnitude
writeOut("Magnitude");
writeVal("|u|", u.mag());
// dot product
writeOut("Dot Product");
writeVal("u*v", u.dot(v));
// normalize
writeOut("Unit Vector");
w = v.unit();
writeVal("v/|v|", w.toString());
// scale
writeOut("Scale");
w = v.scale(50);
writeVal("50v", w.toString());
// scale
writeOut("Normal");
w = v.norm();
writeVal("norm(v)", w.toString());
}
</script>
</body>
</html>