Created
October 20, 2013 17:37
-
-
Save denisdefreyne/7072741 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func pointsAtDistance(a, b, c s5t.Point, d float64) (s5t.Point, s5t.Point) { | |
// Slope of A-B | |
slope := (b.Y - a.Y) / (b.X - a.X) | |
// Slope of line perpendicular to A-B | |
perpSlope := -1 / slope | |
// X components of intersection of circle with radius d with line perpendicular to A-B through C | |
xd := d / math.Sqrt(1+math.Pow(perpSlope, 2.0)) | |
newX1 := c.X + xd | |
newX2 := c.X - xd | |
newY1 := c.Y - perpSlope*(c.X-newX1) | |
newY2 := c.Y - perpSlope*(c.X-newX2) | |
return s5t.Point{X: newX1, Y: newY1}, s5t.Point{X: newX2, Y: newY2} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment