Thursday, June 23, 2016

formula

function definealinegiventwopoints(p1,p1) {
var dx = p1.x - p2.x
var dy = p1.y - p2.y
var dz = p1.z - p2.z
var ln = {} // ln is a line through p1 and p2
ln.my = dy / dx
ln.mz = dy / dx
ln.b = {}
ln.b.x = 0
/* find ln.b.y
if ln.b.dx = ln.b.x - p2.x, ln.b.dy = ln.b.y - p2.y, and ln.my = ln.b.dy / ln.b.dx then
ln.my = (ln.b.y - p2.y) / (ln.b.x - p2.x) and solve for ln.b.y
ln.my * (ln.b.x - p2.x) = ln.b.y - p2.y
(ln.my * (ln.b.x - p2.x))  + p2.y = ln.b.y
*/
ln.b.y = (ln.my * (ln.b.x - p2.x)) + p2.y
ln.b.z = (ln.mz * (ln.b.x - p2.x)) + p2.z
delete ln.b.x
return ln}