hw1
by pkin159
JavaScript
function findline (p) {
return [
p[1].y - p[0].y,
p[0].x-p[1].x,
( p[1].x * p[0].y )-( p[0].x * p[1].y )
];
}
//
// from http://mathworld.wolfram.com/QuadraticEquation.html
//
function linsolve(l) {
return [
((l[1].b * l[0].c) - (l[0].b * l[1].c))/((l[1].a * l[0].b) - (l[0].a * l[1].b)),
((l[1].a * l[0].c) - (l[0].a * l[1].c))/((l[1].a * l[0].b) - (l[0].a * l[1].b)) * (-1)
];
}
//////////////////////////////////////can change line or point
var point = [{
x: 12,y: 6
},
{
x: 7, y: 1
}];
var line = [{ /////////ax + by + c = 0
a:1, b:1, c:1
},{
a:2, b:3, c:2
}]
/////////////////////////////////////////
var roots = findline (point);
//console.log (roots);
var roots2 = linsolve(line);
console.log ('ans1. ' + '(' + roots[0]+')x + ('+ roots[1] + ')y + (' + roots[2] + ') = 0' );
console.log ('ans2. ' + 'x = (' + roots2[0]+ ') ,y = ('+roots2[1] + ')');