So I'm actually following boop boops instructions on this thread: http://www.vbforums.com/showthread.p...nts-to-circles
Here is the code that I've come up with:
However, I keep getting a NaN where I declare my distance variable in the getTangent function. I was assuming to get the distance between the two points it would be(P0 = Point1 and P1 = Point2) the square root of P1.X - P0.X squared plus P1.Y - P0.Y squared. Am I just doing the math wrong or am I using the wrong equation all together?
Here is the code that I've come up with:
Code:
var Point1 = {X:5, Y:5};
var Point2 = {X:10, Y:10};
var Cog1 = {
Point: Point1,
InnerRadius: 5,
OuterRadius: 15
};
var Cog2 = {
Point: Point2,
InnerRadius: 5,
OuterRadius: 15
};
function plotOuter(cogs) {
for (var index = 0; index < cogs.length - 1; index += 1) {
var currentCog = cogs[index];
var nextCog = cogs[index + 1];
var tangent = getTangent(currentCog, nextCog);
}
}
function getTangent(Pn, Pn1) {
var slope = Math.atan2(Pn.OuterRadius, Pn1.OuterRadius);
var distance = Math.sqrt(Math.pow((Pn1.Point.X - Pn.Point.X), 2) + Math.pow((Pn1.Point.Y - Pn.Point.y) ^ 2));
var radiiDifference = Pn1.OuterRadius - Pn.OuterRadius;
var tangentSlope = Math.asin(distance / radiiDifference);
return tangentSlope - slope;
}
window.onload = function() {
plotOuter([Cog1, Cog2]);
};