本文整理汇总了Golang中math.Cos函数的典型用法代码示例。如果您正苦于以下问题:Golang Cos函数的具体用法?Golang Cos怎么用?Golang Cos使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Cos函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GridToGeodetic
//GridToGeodetic converts RT90 coordinates to WGS84
func GridToGeodetic(x, y float64) (float64, float64) {
if CentralMeridian == 31337.0 {
return 0.0, 0.0
}
e2 := Flattening * (2.0 - Flattening)
n := Flattening / (2.0 - Flattening)
a_roof := Axis / (1.0 + n) * (1.0 + n*n/4.0 + n*n*n*n/64.0)
delta1 := n/2.0 - 2.0*n*n/3.0 + 37.0*n*n*n/96.0 - n*n*n*n/360.0
delta2 := n*n/48.0 + n*n*n/15.0 - 437.0*n*n*n*n/1440.0
delta3 := 17.0*n*n*n/480.0 - 37*n*n*n*n/840.0
delta4 := 4397.0 * n * n * n * n / 161280.0
Astar := e2 + e2*e2 + e2*e2*e2 + e2*e2*e2*e2
Bstar := -(7.0*e2*e2 + 17.0*e2*e2*e2 + 30.0*e2*e2*e2*e2) / 6.0
Cstar := (224.0*e2*e2*e2 + 889.0*e2*e2*e2*e2) / 120.0
Dstar := -(4279.0 * e2 * e2 * e2 * e2) / 1260.0
DegToRad := math.Pi / 180
LambdaZero := CentralMeridian * DegToRad
xi := (x - FalseNorthing) / (Scale * a_roof)
eta := (y - FalseEasting) / (Scale * a_roof)
xi_prim := xi - delta1*math.Sin(2.0*xi)*math.Cosh(2.0*eta) - delta2*math.Sin(4.0*xi)*math.Cosh(4.0*eta) - delta3*math.Sin(6.0*xi)*math.Cosh(6.0*eta) - delta4*math.Sin(8.0*xi)*math.Cosh(8.0*eta)
eta_prim := eta - delta1*math.Cos(2.0*xi)*math.Sinh(2.0*eta) - delta2*math.Cos(4.0*xi)*math.Sinh(4.0*eta) - delta3*math.Cos(6.0*xi)*math.Sinh(6.0*eta) - delta4*math.Cos(8.0*xi)*math.Sinh(8.0*eta)
phi_star := math.Asin(math.Sin(xi_prim) / math.Cosh(eta_prim))
delta_lambda := math.Atan(math.Sinh(eta_prim) / math.Cos(xi_prim))
lon_radian := LambdaZero + delta_lambda
lat_radian := phi_star + math.Sin(phi_star)*math.Cos(phi_star)*(Astar+Bstar*math.Pow(math.Sin(phi_star), 2)+Cstar*math.Pow(math.Sin(phi_star), 4)+Dstar*math.Pow(math.Sin(phi_star), 6))
return lat_radian * 180.0 / math.Pi, lon_radian * 180.0 / math.Pi
}
示例2: drawCircle
func drawCircle(x, y, r float64) {
//@TODO: Should speed this up by pre-computing all these cos() and sin() calculations and storing in a lookup table.
gl.Begin(gl.TRIANGLE_FAN)
// gl.Color3d(me.red, me.green, me.blue)
gl.Vertex2d(x, y)
pi2 := 2 * math.Pi
num := 36
dTheta := pi2 / float64(num)
theta := float64(0)
for i := 0; i < num; i++ {
theta += dTheta
dx := math.Cos(theta) * r
dy := math.Sin(theta) * r
gl.Vertex2d(x+dx, y+dy)
}
theta += dTheta
dx := math.Cos(theta) * r
dy := math.Sin(theta) * r
gl.Vertex2d(x+dx, y+dy)
gl.End()
}
示例3: Arc
// Arc draws an arc with a positive angle (clockwise)
func Arc(gc draw2d.GraphicContext, xc, yc, width, height float64) {
// draw an arc
xc += width / 2
yc += height / 2
radiusX, radiusY := width/2, height/2
startAngle := 45 * (math.Pi / 180.0) /* angles are specified */
angle := 135 * (math.Pi / 180.0) /* clockwise in radians */
gc.SetLineWidth(width / 10)
gc.SetLineCap(draw2d.ButtCap)
gc.SetStrokeColor(image.Black)
gc.MoveTo(xc+math.Cos(startAngle)*radiusX, yc+math.Sin(startAngle)*radiusY)
gc.ArcTo(xc, yc, radiusX, radiusY, startAngle, angle)
gc.Stroke()
// fill a circle
gc.SetStrokeColor(color.NRGBA{255, 0x33, 0x33, 0x80})
gc.SetFillColor(color.NRGBA{255, 0x33, 0x33, 0x80})
gc.SetLineWidth(width / 20)
gc.MoveTo(xc+math.Cos(startAngle)*radiusX, yc+math.Sin(startAngle)*radiusY)
gc.LineTo(xc, yc)
gc.LineTo(xc-radiusX, yc)
gc.Stroke()
gc.MoveTo(xc, yc)
gc.ArcTo(xc, yc, width/10.0, height/10.0, 0, 2*math.Pi)
gc.Fill()
}
示例4: PointAtDistanceAndBearing
// Returns a Point populated with the lat and lng coordinates of transposing the origin point the distance (in meters) supplied by the compass bearing (in degrees) supplied.
// Original Implementation from: http://www.movable-type.co.uk/scripts/latlong.html
func (p *Point) PointAtDistanceAndBearing(dist float64, bearing float64) *Point {
dr := dist / EARTH_RADIUS
bearing = (bearing * (math.Pi / 180.0))
lat1 := (p.lat * (math.Pi / 180.0))
lng1 := (p.lng * (math.Pi / 180.0))
lat2_part1 := math.Sin(lat1) * math.Cos(dr)
lat2_part2 := math.Cos(lat1) * math.Sin(dr) * math.Cos(bearing)
lat2 := math.Asin(lat2_part1 + lat2_part2)
lng2_part1 := math.Sin(bearing) * math.Sin(dr) * math.Cos(lat1)
lng2_part2 := math.Cos(dr) - (math.Sin(lat1) * math.Sin(lat2))
lng2 := lng1 + math.Atan2(lng2_part1, lng2_part2)
lng2 = math.Mod((lng2+3*math.Pi), (2*math.Pi)) - math.Pi
lat2 = lat2 * (180.0 / math.Pi)
lng2 = lng2 * (180.0 / math.Pi)
return &Point{lat: lat2, lng: lng2}
}
示例5: partialArc
// Approximate a circular arc of fewer than π/2
// radians with cubic Bézier curve.
func partialArc(p *pdf.Path, x, y, r vg.Length, a1, a2 float64) {
a := (a2 - a1) / 2
x4 := r * vg.Length(math.Cos(a))
y4 := r * vg.Length(math.Sin(a))
x1 := x4
y1 := -y4
const k = 0.5522847498 // some magic constant
f := k * vg.Length(math.Tan(a))
x2 := x1 + f*y4
y2 := y1 + f*x4
x3 := x2
y3 := -y2
// Rotate and translate points into position.
ar := a + a1
sinar := vg.Length(math.Sin(ar))
cosar := vg.Length(math.Cos(ar))
x2r := x2*cosar - y2*sinar + x
y2r := x2*sinar + y2*cosar + y
x3r := x3*cosar - y3*sinar + x
y3r := x3*sinar + y3*cosar + y
x4 = r*vg.Length(math.Cos(a2)) + x
y4 = r*vg.Length(math.Sin(a2)) + y
p.Curve(pdfPoint(x2r, y2r), pdfPoint(x3r, y3r), pdfPoint(x4, y4))
}
示例6: Initialize
func (m *mbody) Initialize() (y0 []float64) {
n := len(m.mass)
y0 = make([]float64, n*6)
rf1 := 4 * math.Pi / 8
rf2 := 2 * math.Pi / float64(n)
for i := range m.mass {
i1 := float64(i + 1)
m.mass[i] = (0.3 + 0.1*(math.Cos(i1*rf1)+1.0)) / float64(n)
rad := 1.7 + math.Cos(i1*0.75)
v := 0.22 * math.Sqrt(rad)
ci := math.Cos(i1 * rf2)
si := math.Sin(i1 * rf2)
ip := 6 * i
y0[ip] = rad * ci
y0[ip+1] = rad * si
y0[ip+2] = 0.4 * si
y0[ip+3] = -v * si
y0[ip+4] = v * ci
y0[ip+5] = 0
}
return
}
示例7: delayGPS
func delayGPS(source string, destination string) (int, error) {
src := strings.Split(source, "/")
lat1, err := strconv.ParseFloat(src[0], 64)
if err != nil {
return -1, err
}
lon1, err := strconv.ParseFloat(src[1], 64)
if err != nil {
return -1, err
}
dest := strings.Split(destination, "/")
lat2, err := strconv.ParseFloat(dest[0], 64)
if err != nil {
return -1, err
}
lon2, err := strconv.ParseFloat(dest[1], 64)
if err != nil {
return -1, err
}
radius := float64(6371)
dlat := (lat2 - lat1) / (180 / math.Pi)
dlon := (lon2 - lon1) / (180 / math.Pi)
a := math.Sin(dlat/2)*math.Sin(dlat/2) + math.Cos(lat1/(180*math.Pi))*math.Cos(lat2/(180*math.Pi))*math.Sin(dlon/2)*math.Sin(dlon/2)
c := 2 * math.Atan2(math.Sqrt(a), math.Sqrt(1-a))
d := radius * c
speed := float64(139)
return int(math.Floor(d/speed + 0.5)), nil
}
示例8: gradient
func gradient(x float64, y float64) (xd float64, yd float64) {
xd = (2 * x * math.Cos(math.Pow(x, 2)+math.Pow(y, 2)) * math.Cos(y+math.Exp(x))) -
(math.Exp(x) * math.Sin(math.Pow(x, 2)+math.Pow(y, 2)) * math.Sin(y+math.Exp(x)))
yd = (2 * y * math.Cos(math.Pow(x, 2)+math.Pow(y, 2)) * math.Cos(y+math.Exp(x))) -
(math.Sin(math.Pow(x, 2)+math.Pow(y, 2)) * math.Sin(y+math.Exp(x)))
return
}
示例9: Paths
func (c *OutlineCone) Paths() Paths {
center := Vector{0, 0, 0}
hyp := center.Sub(c.Eye).Length()
opp := c.Radius
theta := math.Asin(opp / hyp)
adj := opp / math.Tan(theta)
d := math.Cos(theta) * adj
// r := math.Sin(theta) * adj
w := center.Sub(c.Eye).Normalize()
u := w.Cross(c.Up).Normalize()
c0 := c.Eye.Add(w.MulScalar(d))
a0 := c0.Add(u.MulScalar(c.Radius * 1.01))
b0 := c0.Add(u.MulScalar(-c.Radius * 1.01))
var p0 Path
for a := 0; a < 360; a++ {
x := c.Radius * math.Cos(Radians(float64(a)))
y := c.Radius * math.Sin(Radians(float64(a)))
p0 = append(p0, Vector{x, y, 0})
}
return Paths{
p0,
{{a0.X, a0.Y, 0}, {0, 0, c.Height}},
{{b0.X, b0.Y, 0}, {0, 0, c.Height}},
}
}
示例10: AssignEulerRotation
// AssignEulerRotation assigns Euler angle rotations to the rotation part of the matrix and sets the remaining elements to their ident value.
func (mat *T) AssignEulerRotation(yHead, xPitch, zRoll float64) *T {
sinH := math.Sin(yHead)
cosH := math.Cos(yHead)
sinP := math.Sin(xPitch)
cosP := math.Cos(xPitch)
sinR := math.Sin(zRoll)
cosR := math.Cos(zRoll)
mat[0][0] = cosR*cosH - sinR*sinP*sinH
mat[1][0] = -sinR * cosP
mat[2][0] = cosR*sinH + sinR*sinP*cosH
mat[3][0] = 0
mat[0][1] = sinR*cosH + cosR*sinP*sinH
mat[1][1] = cosR * cosP
mat[2][1] = sinR*sinH - cosR*sinP*cosH
mat[3][1] = 0
mat[0][2] = -cosP * sinH
mat[1][2] = sinP
mat[2][2] = cosP * cosH
mat[3][2] = 0
mat[0][3] = 0
mat[1][3] = 0
mat[2][3] = 0
mat[3][3] = 1
return mat
}
示例11: readSphereNormal
func readSphereNormal(r io.Reader) (Vec3, error) {
var result Vec3
var zenith uint8
var azimuth uint8
var err error
zenith, err = readU8(r)
if err != nil {
return result, err
}
azimuth, err = readU8(r)
if err != nil {
return result, err
}
latitude := float64(zenith) * (math.Pi * 2.0) / 255.0
longitude := float64(azimuth) * (math.Pi * 2.0) / 255.0
latsin := math.Sin(latitude)
result.X = float32(math.Cos(longitude) * latsin)
result.Y = float32(math.Sin(longitude) * latsin)
result.Z = float32(math.Cos(latitude))
return result, nil
}
示例12: distance
func distance(p1, p2 location) float64 {
var dlat float64 = p1.lat - p2.lat
var dlong float64 = p1.long - p2.long
var a float64 = math.Pow(math.Sin(dlat/2), 2) + math.Cos(p1.lat)*math.Cos(p2.lat)*math.Pow(math.Sin(dlong/2), 2)
return 2 * R * math.Atan2(math.Sqrt(a), math.Sqrt(1-a))
}
示例13: drawCurve
func (i img) drawCurve(c curve) {
red := byte((c.color >> 16))
green := byte((c.color >> 8))
blue := byte(c.color)
startAngle := c.start * 2 * math.Pi
angle := (c.end - c.start) * 2 * math.Pi
endAngle := startAngle + angle
radius := float64(c.level * i.levelWidth)
radiusOuter := radius + float64(i.levelWidth)
i.ctx.SetStrokeColor(color.RGBA{0, 0, 0, 0})
i.ctx.SetFillColor(color.RGBA{red, green, blue, 0xFF})
i.ctx.MoveTo(
i.centerX+math.Cos(startAngle)*radius,
i.centerY+math.Sin(startAngle)*radius,
)
i.ctx.ArcTo(i.centerX, i.centerY, radius, radius, startAngle, angle)
i.ctx.LineTo(
i.centerX+math.Cos(endAngle)*radiusOuter,
i.centerY+math.Sin(endAngle)*radiusOuter,
)
i.ctx.ArcTo(i.centerX, i.centerY, radiusOuter, radiusOuter, endAngle, -angle)
i.ctx.LineTo(
i.centerX+math.Cos(startAngle)*radius,
i.centerY+math.Sin(startAngle)*radius,
)
i.ctx.FillStroke()
}
示例14: generate_polyline_code
// from: http://stackoverflow.com/questions/7316963/drawing-a-circle-google-static-maps
func (t *MealServlet) generate_polyline_code(lat, lng float64) string {
r_earth := 6371000
pi := math.Pi
lat = (lat * pi) / 180
lng = (lng * pi) / 180
d := float64(250) / float64(r_earth) // diameter of circle
points := make([]*Point, 0)
// generate the points. Adjust granularity using the incrementor
for i := 0; i <= 360; i++ {
brng := float64(i) * pi / float64(180)
log.Println(i)
p_lat := math.Asin(math.Sin(lat)*math.Cos(d) + math.Cos(lat)*math.Sin(d)*math.Cos(brng))
p_lng := ((lng + math.Atan2(math.Sin(brng)*math.Sin(d)*math.Cos(lat),
math.Cos(d)-math.Sin(lat)*math.Sin(p_lat))) * 180) / pi
p_lat = (p_lat * 180) / pi
point := new(Point)
point.Lat = p_lat
point.Lng = p_lng
log.Println(p_lat)
log.Println(p_lng)
points = append(points, point)
}
return EncodePolyline(points)
}
示例15: RotY
// RotY returns a rotation matrix rotating r degrees around the y axis.
func RotY(r float64) Mat4 {
r *= deg
return Mat4{[4]float64{math.Cos(r), 0, math.Sin(r), 0},
[4]float64{0, 1, 0, 0},
[4]float64{-math.Sin(r), 0, math.Cos(r), 0},
[4]float64{0, 0, 0, 1}}
}