Skip to content

Commit 828cacc

Browse files
committed
Add A.hat and hat(A), equivalent to A.norm() and norm(A); A.hat is easier to type than A.norm()
1 parent d9c5f29 commit 828cacc

4 files changed

Lines changed: 20 additions & 6 deletions

File tree

docs/GlowScriptDocs/vector.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ <h1 class="Heading-1"> <font color="#0000a0">The vector object</font></h1>
6161
<strong>mag2(A) = A.mag2</strong> = |A|*|A|, the vector's magnitude squared<br />
6262
<br />
6363
<strong>norm(A) = A.norm()</strong> = A/|A|, a unit vector in the direction of the vector<br />
64+
<br />
65+
<strong>hat(A) = A.hat</strong> =
66+
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 &quot;hat&quot; over the vector<br />
6467
<br />
6568
<strong>dot(A,B) = A.dot(B)</strong> = A dot B, the scalar dot product between two vectors<br />
6669
<br />

docs/VPythonDocs/vector.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ <h1 class="Heading-1"> <font color="#0000a0">The vector Object</font></h1>
6969
<strong>mag2(A) = A.mag2</strong> = |A|*|A|, the vector's magnitude squared<br />
7070
<br />
7171
<strong>norm(A) = A.norm()</strong> = A/|A|, a unit vector in the direction of the vector<br />
72+
<br />
73+
<strong>hat(A) = A.hat</strong> =
74+
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 &quot;hat&quot; over the vector<br />
7275
<br />
7376
<strong>dot(A,B) = A.dot(B)</strong> = A dot B, the scalar dot product between two vectors<br />
7477
<br />

lib/glow/vectors.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,10 @@
309309
mag2: {
310310
get: function () { return this.x * this.x + this.y * this.y + this.z * this.z },
311311
set: function (value) { return this.norm().multiply(Math.sqrt(value)) }
312+
},
313+
hat: {
314+
get: function () { return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z) },
315+
set: function (value) { throw new Error("Cannot assign a value to v.hat") }
312316
}
313317
})
314318

@@ -421,6 +425,9 @@
421425
function norm(A) {
422426
return A.norm();
423427
}
428+
function hat(A) {
429+
return A.hat;
430+
}
424431
function dot(A,B) {
425432
return A.dot(B);
426433
}
@@ -458,6 +465,7 @@
458465
mag: mag,
459466
mag2: mag2,
460467
norm: norm,
468+
hat: hat,
461469
dot: dot,
462470
cross: cross,
463471
comp: comp,

package/glow.2.1.min.js

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)