func (cs *CoordinateSystem) Inverse(xyz *globals.XYZ) *globals.PLH { xyz.X = (xyz.X*cs.FloatParams["to_meter"] - cs.FloatParams["x_0"]) * cs.FloatParams["ra"] xyz.Y = (xyz.Y*cs.FloatParams["to_meter"] - cs.FloatParams["y_0"]) * cs.FloatParams["ra"] plh := cs.Projection.Inverse(cs.FloatParams, xyz) plh.Lam = plh.Lam + cs.FloatParams["lam0"] if !cs.BoolParams["over"] { plh.Lam = cs.adjlon(plh.Lam) } return plh }
func StereaInverse(params map[string]float64, xyz *globals.XYZ) *globals.PLH { // x, y float64) (lat, lon float64) { splh := &globals.PLH{} // sterea const MAX_ITER = 20 const DEL_TOL = 1e-14 xyz.X = xyz.X / params["k"] xyz.Y = xyz.Y / params["k"] rho := math.Hypot(xyz.X, xyz.Y) if rho != 0 { c := 2.0 * math.Atan2(rho, params["2R"]) sinc := math.Sin(c) cosc := math.Cos(c) splh.Phi = math.Asin(cosc*params["sinc0"] + xyz.Y*sinc*params["cosc0"]/rho) splh.Lam = math.Atan2(xyz.X*sinc, rho*params["cosc0"]*cosc-xyz.Y*params["sinc0"]*sinc) } else { splh.Phi = params["latc0"] splh.Lam = 0.0 } // inv_gaus eplh := &globals.PLH{} eplh.Lam = splh.Lam / params["C"] num := math.Pow(math.Tan(0.5*splh.Phi+globals.PI_OVER_4)/params["K"], 1.0/params["C"]) var i uint8 for i = 0; i < MAX_ITER; i++ { eplh.Phi = 2.0*math.Atan(num*srat(params["e"]*math.Sin(splh.Phi), -0.5*params["e"])) - globals.PI_OVER_2 if math.Abs(eplh.Phi-splh.Phi) < DEL_TOL { break } splh.Phi = eplh.Phi } if i == MAX_ITER-1 { fmt.Printf("Convergence failed") } eplh.Height = xyz.Z return eplh }