Skip to content

Instantly share code, notes, and snippets.

@zone117x
Created September 14, 2015 14:18
Show Gist options
  • Select an option

  • Save zone117x/26ff4bf00ad0b99bca8d to your computer and use it in GitHub Desktop.

Select an option

Save zone117x/26ff4bf00ad0b99bca8d to your computer and use it in GitHub Desktop.
C# Point between two points
static void CalculateBetweenPoint(double x1, double y1, double x2, double y2, double distance, out double x3, out double y3)
{
var xDistance = Math.Abs(x1 - x2);
var yDistance = Math.Abs(x2 - y2);
var distanceAB = Math.Sqrt(Math.Pow(xDistance, 2) + Math.Pow(yDistance, 2));
var angleAB = Math.Atan2(y2 - y1, x2 - x1);
var deltaXAC = distance * Math.Cos(angleAB);
var deltaYAC = distance * Math.Sin(angleAB);
x3 = x1 + deltaXAC;
y3 = y1 + deltaYAC;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment