Advertisement
cwchen

[Go] Calculating the distance between two points w/ struct.

Sep 19th, 2017
1,301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.26 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5.     "math"
  6. )
  7.  
  8. type Point struct {
  9.     x float64
  10.     y float64
  11. }
  12.  
  13. func main() {
  14.     p := Point{x: 3.0, y: 4.0}
  15.     q := Point{x: 0.0, y: 0.0}
  16.  
  17.     distance := math.Sqrt(math.Pow(p.x-q.x, 2) + math.Pow(p.y-q.y, 2))
  18.     fmt.Println(distance)
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement