You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
//f + (t -f) * a
function interpolateTriangleSide(from, to, mouse)
{
var percentY = (mouse.y - to.y) / (from.y - to.y);
console.log(percentY);
var cX = from.x + (to.x - from.x) * percentY;
return cX;
}
var from = {
x : 100,
y : 600
};
var to = {
x : 0,
y : 0
};
var mouse = {
x : 900,
y : 150
};
console.log(interpolateTriangleSide(from, to, mouse));
check outside (khanacademy)
var p = {
x : 228,
y : 226
};
ellipse(p.x, p.y, 10, 10);
var scnd = {
x : 100, y: 200
};
var first = {
x : 200, y: 200
};
var third = {
x : 150, y: 100
};
var baseX = first.x - scnd.x;
var baseY = first.y;
var left = p.x < scnd.x + (baseX / 2);
var interpolateTriangleSide = function(from, to, mousee) {
var percentY = (mousee.y - to.y) / (from.y - to.y);
var cX = to.x + (from.x - to.x) * percentY;
return cX;
};
if(p.y > scnd.y)
{
//Bottom
if(p.x > scnd.x && p.x < first.x)
{
//Bottom, middle
p = {
x : p.x,
y : scnd.y
};
}
else
{
//Bottom, lock to either left or right
if(left)
{
p = {
x : scnd.x,
y : scnd.y
};
}
else
{
p = {
x : first.x,
y : first.y
};
}
}
}
else if(p.y < third.y)
{
//Top
p = {
x : third.x,
y : third.y
};
}
else if(p.y <= scnd.y)
{
//Middle, interpolation
var cX;
if(left) {
cX = interpolateTriangleSide(scnd, third, p);
}
else {
cX = interpolateTriangleSide(first, third, p);
}
println(cX + ", " + scnd.x);
p.x = cX;
}
triangle(first.x, first.y, scnd.x, scnd.y, third.x, third.y);
ellipse(p.x, p.y, 5, 5);