Skip to content

Instantly share code, notes, and snippets.

@Nullpo
Created December 2, 2015 20:36
Show Gist options
  • Select an option

  • Save Nullpo/b846e6e9dc658ee80d04 to your computer and use it in GitHub Desktop.

Select an option

Save Nullpo/b846e6e9dc658ee80d04 to your computer and use it in GitHub Desktop.
obtener funcion lineal a partir de dos puntos.
var Punto = function(x,y){
return { x: x, y: y };
}
function obtenerRecta(p1, p2){
var x1 = p1.y;
var y1 = p1.y;
var x2 = p2.x;
var y2 = p2.y;
var difY = y1 - y2;
var difX = -x2 + x1;
var a = difY / difX;
var b = y1 - a * x1;
return function Recta(x){
return a * x + b;
};
}
// example:
var f = obtenerRecta({
x:0,
y:0
}, {
x:1,
y:2
})
f(2); // returns f(2) = 4
f(3); // returns f(3) = 6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment