本文记录使用 Go 语言实现 RESTful 的点坐标的转换。
极坐标与笛卡尔坐标的数学关系
假设同一个点使用极坐标表示为 (ρ, θ), 使用笛卡尔坐标表示为(x,y),那么,这些数学符号之间,有如下关系
x = ρ* Cosθ
y = ρ* Sinθ
ρ= Sqrt(x*x+y*y)
θ = Arctan(x/y)
Go语言实现/** @Author: coolwp.com* @Date: 2017-09-12 16:25:34* @Last Modified by: suifengtec* @Last Modified time: 2017-09-12 16:41:35**//*go build -o a.exe main.go*/package mainimport ("encoding/json""fmt""github.com/gorilla/mux""log""math""net/http""strconv""strings")type DotJ struct {R float64 `json:"r"`A float64 `json:"a"`}type DotD struct {X float64 `json:"x"`Y float64 `json:"y"`}/*type DotJs []DotJtype DotDs []DotD*//*http://127.0.0.1:6688/d/12/5{"r":13,"a":22.61986}*/func doD(w http.ResponseWriter, r *http.Request) {vars := mux.Vars(r)errV :=