Last active
February 20, 2017 21:59
-
-
Save 0xcaff/15753929fb8766931f61c100330a788c to your computer and use it in GitHub Desktop.
Calculus III Project I
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
==> question2a.txt <== | |
Distance: 89/sqrt(1635) | |
==> question2b.txt <== | |
Distance: 40/sqrt(104) | |
==> question2c.txt <== | |
Distance: 64/sqrt(222) | |
==> question3.txt <== | |
Equation: -5(x - 3) + -10(y + 1) + 5(z - 2) = 0 | |
==> question4.txt <== | |
Equation: -5(x - 4) + -10(y - 0) + 5(z - 3) = 0 | |
==> question5.txt <== | |
Equation: -5(x - 5) + -10(y - 1) + 5(z - 4) = 0 | |
==> question6.txt <== | |
Equation: -5(x - 6) + -10(y - 2) + 5(z - 5) = 0 | |
==> question7.txt <== | |
Equation: -5(x - 7) + -10(y - 3) + 5(z - 6) = 0 | |
==> question8.txt <== | |
Area: sqrt(150) | |
==> question9.txt <== | |
Area: sqrt(150) | |
==> question10.txt <== | |
Area: sqrt(150) | |
==> question11.txt <== | |
Area: sqrt(150) | |
==> question12.txt <== | |
Area: sqrt(150) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function vector(from, to) { | |
return { | |
x: to.x - from.x, | |
y: to.y - from.y, | |
z: to.z - from.z, | |
}; | |
} | |
function crossProduct(u, v) { | |
return { | |
x: u.y * v.z - v.y * u.z, | |
y: -(u.x * v.z - v.x * u.z), | |
z: u.x * v.y - v.x * u.y, | |
}; | |
} | |
function signed(num) { | |
if (num > 0) { | |
return "+ " + num; | |
} else { | |
return "- " + (-num).toString(); | |
} | |
} | |
function mag2(vec) { | |
return vec.x * vec.x + vec.y * vec.y + vec.z * vec.z; | |
} | |
// // question 8 | |
// const a = {x: 3, y: -1, z: 2}; | |
// const b = {x: 2, y: 1, z: 5}; | |
// const c = {x: 1, y: -2, z: -2}; | |
// // question 9 | |
// const a = {x: 4, y: 0, z: 3}; | |
// const b = {x: 3, y: 2, z: 6}; | |
// const c = {x: 2, y: -1, z: -1}; | |
// // question 10 | |
// const a = {x: 5, y: 1, z: 4}; | |
// const b = {x: 4, y: 3, z: 7}; | |
// const c = {x: 3, y: 0, z: 0}; | |
// // question 11 | |
// const a = {x: 6, y: 2, z: 5}; | |
// const b = {x: 5, y: 4, z: 8}; | |
// const c = {x: 4, y: 1, z: 1}; | |
// question 12 | |
const a = {x: 7, y: 3, z: 6}; | |
const b = {x: 6, y: 5, z: 9}; | |
const c = {x: 5, y: 2, z: 2}; | |
const AB = vector(a, b); | |
const AC = vector(a, c); | |
const n = crossProduct(AB, AC); | |
console.log(`Area: sqrt(${mag2(n)})`); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function vector(from, to) { | |
return { | |
x: to.x - from.x, | |
y: to.y - from.y, | |
z: to.z - from.z, | |
}; | |
} | |
function crossProduct(u, v) { | |
return { | |
x: u.y * v.z - v.y * u.z, | |
y: -(u.x * v.z - v.x * u.z), | |
z: u.x * v.y - v.x * u.y, | |
}; | |
} | |
function signed(num) { | |
if (num > 0) { | |
return "+ " + num; | |
} else { | |
return "- " + (-num).toString(); | |
} | |
} | |
// question 3 | |
const a = {x: 3, y: -1, z: 2}; | |
const b = {x: 2, y: 1, z: 5}; | |
const c = {x: 1, y: -2, z: -2}; | |
// question 4 | |
// const a = {x: 4, y: 0, z: 3}; | |
// const b = {x: 3, y: 2, z: 6}; | |
// const c = {x: 2, y: -1, z: -1}; | |
// question 5 | |
// const a = {x: 5, y: 1, z: 4}; | |
// const b = {x: 4, y: 3, z: 7}; | |
// const c = {x: 3, y: 0, z: 0}; | |
// question 6 | |
// const a = {x: 6, y: 2, z: 5}; | |
// const b = {x: 5, y: 4, z: 8}; | |
// const c = {x: 4, y: 1, z: 1}; | |
// question 7 | |
// const a = {x: 7, y: 3, z: 6}; | |
// const b = {x: 6, y: 5, z: 9}; | |
// const c = {x: 5, y: 2, z: 2}; | |
const AB = vector(a, b); | |
const AC = vector(a, c); | |
const n = crossProduct(AB, AC); | |
console.log(`Equation: ${n.x}(x ${signed(-a.x)}) + ${n.y}(y ${signed(-a.y)}) + ${n.z}(z ${signed(-a.z)}) = 0`); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function crossProduct(u, v) { | |
return { | |
x: u.y * v.z - v.y * u.z, | |
y: -(u.x * v.z - v.x * u.z), | |
z: u.x * v.y - v.x * u.y, | |
}; | |
} | |
function dotProduct(u, v) { | |
return u.x * v.x + u.y * v.y + u.z * v.z; | |
} | |
function mag2(vec) { | |
return vec.x * vec.x + vec.y * vec.y + vec.z * vec.z; | |
} | |
function vector(from, to) { | |
return { | |
x: to.x - from.x, | |
y: to.y - from.y, | |
z: to.z - from.z, | |
}; | |
} | |
function abs(num) { | |
if (num > 0) { | |
return num; | |
} else { | |
return -num; | |
} | |
} | |
// question 2.a | |
const l1 = {x: 5, y: 5, z: -4}; | |
const l2 = {x: 1, y: 8, z: -3}; | |
const p = {x: 4, y: 5, z: 1}; | |
const q = {x: 4, y: -6, z: 7}; | |
// question 2.b | |
// const l1 = {x: 2, y: 4, z: 6}; | |
// const l2 = {x: -1, y: 1, z: 1}; | |
// | |
// const p = {x: 0, y: 0, z: 0}; | |
// const q = {x: 1, y: 4, z: -1}; | |
// // question 2.c | |
// const l1 = {x: 3, y: -1, z: 1}; | |
// const l2 = {x: 4, y: 1, z: -3}; | |
// | |
// const p = {x: 0, y: 2, z: -1}; | |
// const q = {x: 1, y: -2, z: -3}; | |
const pq = vector(p, q); | |
const n = crossProduct(l1, l2); | |
// project pq onto n then take magnitude | |
console.log(`Distance: ${abs(dotProduct(n, pq))}/sqrt(${mag2(n)})`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment