Skip to content

Instantly share code, notes, and snippets.

@denisdefreyne
Created October 20, 2013 17:37
Show Gist options
  • Save denisdefreyne/7072741 to your computer and use it in GitHub Desktop.
Save denisdefreyne/7072741 to your computer and use it in GitHub Desktop.
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