本文整理汇总了Golang中math.Sin函数的典型用法代码示例。如果您正苦于以下问题:Golang Sin函数的具体用法?Golang Sin怎么用?Golang Sin使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Sin函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ExamplePMod_integer
// Section "Trigonometric functions of large angles":
//
// Meeus makes his point, but an example with integer values is a bit unfair
// when trigonometric functions inherently work on floating point numbers.
func ExamplePMod_integer() {
const large = 36000030
// The direct function call loses precition as expected.
fmt.Println("Direct: ", math.Sin(large*math.Pi/180))
// When the value is manually reduced to the integer 30, the Go constant
// evaluaton does a good job of delivering a radian value to math.Sin that
// evaluates to .5 exactly.
fmt.Println("Integer 30:", math.Sin(30*math.Pi/180))
// Math.Mod takes float64s and returns float64s. The integer constants
// here however can be represented exactly as float64s, and the returned
// result is exact as well.
fmt.Println("Math.Mod: ", math.Mod(large, 360))
// But when math.Mod is substituted into the Sin function, float64s
// are multiplied instead of the high precision constants, and the result
// comes back slightly inexact.
fmt.Println("Sin Mod: ", math.Sin(math.Mod(large, 360)*math.Pi/180))
// Use of PMod on integer constants produces results identical to above.
fmt.Println("PMod int: ", math.Sin(base.PMod(large, 360)*math.Pi/180))
// As soon as the large integer is scaled to a non-integer value though,
// precision is lost and PMod is of no help recovering at this point.
fmt.Println("PMod float:", math.Sin(base.PMod(large*math.Pi/180, 2*math.Pi)))
// Output:
// Direct: 0.49999999995724154
// Integer 30: 0.5
// Math.Mod: 30
// Sin Mod: 0.49999999999999994
// PMod int: 0.49999999999999994
// PMod float: 0.49999999997845307
}
示例2: lissajous
func lissajous(out http.ResponseWriter, r *http.Request) {
const (
cycles = 5
res = 0.001
size = 100
nframes = 64
delay = 8
)
freq := rand.Float64() * 3.0
anim := gif.GIF{LoopCount: nframes}
phase := 0.0
for i := 0; i < nframes; i++ {
rect := image.Rect(0, 0, 2*size+1, 2*size+1)
img := image.NewPaletted(rect, palette)
for t := 0.0; t < cycles*2*math.Pi; t += res {
x := math.Sin(t)
y := math.Sin(t*freq + phase)
img.SetColorIndex(size+int(x*size+0.5), size+int(y*size+0.5), blackIndex)
}
phase += 0.1
anim.Delay = append(anim.Delay, delay)
anim.Image = append(anim.Image, img)
}
gif.EncodeAll(out, &anim)
}
示例3: lissajous
func lissajous(out io.Writer) {
const (
cycles = 5 // number of complete x oscillator revolutions
res = 0.001 // angular resolution
size = 100 // image canvas covers [-size..+size]
nframes = 64 // number of animation frames
delay = 8 // delay between frames in 10ms units
)
freq := rand.Float64() * 3.0 // relative frequency of y oscillator
anim := gif.GIF{LoopCount: nframes}
phase := 0.0 // phase difference
for i := 0; i < nframes; i++ {
rect := image.Rect(0, 0, 2*size+1, 2*size+1)
img := image.NewPaletted(rect, palette)
for t := 0.0; t < cycles*2*math.Pi; t += res {
x := math.Sin(t)
y := math.Sin(t*freq + phase)
img.SetColorIndex(size+int(x*size+0.5), size+int(y*size+0.5), uint8(i)%3+1)
}
phase += 0.1
anim.Delay = append(anim.Delay, delay)
anim.Image = append(anim.Image, img)
}
gif.EncodeAll(out, &anim) // NOTE: ignoring encoding errors
}
示例4: hyperion
func (q *qs) hyperion() (r r4) {
η := 92.39*d + .5621071*d*q.t6
ζ := 148.19*d - 19.18*d*q.t8
θ := 184.8*d - 35.41*d*q.t9
θʹ := θ - 7.5*d
as := 176*d + 12.22*d*q.t8
bs := 8*d + 24.44*d*q.t8
cs := bs + 5*d
ϖ := 69.898*d - 18.67088*d*q.t8
φ := 2 * (ϖ - q.W5)
χ := 94.9*d - 2.292*d*q.t8
sη, cη := math.Sincos(η)
sζ, cζ := math.Sincos(ζ)
s2ζ, c2ζ := math.Sincos(2 * ζ)
s3ζ, c3ζ := math.Sincos(3 * ζ)
sζpη, cζpη := math.Sincos(ζ + η)
sζmη, cζmη := math.Sincos(ζ - η)
sφ, cφ := math.Sincos(φ)
sχ, cχ := math.Sincos(χ)
scs, ccs := math.Sincos(cs)
a := 24.50601 - .08686*cη - .00166*cζpη + .00175*cζmη
e := .103458 - .004099*cη - .000167*cζpη + .000235*cζmη +
.02303*cζ - .00212*c2ζ + 0.000151*c3ζ + .00013*cφ
p := ϖ + .15648*d*sχ - .4457*d*sη - .2657*d*sζpη - .3573*d*sζmη -
12.872*d*sζ + 1.668*d*s2ζ - .2419*d*s3ζ - .07*d*sφ
λʹ := 177.047*d + 16.91993829*d*q.t6 + .15648*d*sχ + 9.142*d*sη +
.007*d*math.Sin(2*η) - .014*d*math.Sin(3*η) + .2275*d*sζpη +
.2112*d*sζmη - .26*d*sζ - .0098*d*s2ζ -
.013*d*math.Sin(as) + .017*d*math.Sin(bs) - .0303*d*sφ
i := 27.3347*d + .6434886*d*cχ + .315*d*q.cW3 + .018*d*math.Cos(θ) -
.018*d*ccs
Ω := 168.6812*d + 1.40136*d*cχ + .68599*d*q.sW3 - .0392*d*scs +
.0366*d*math.Sin(θʹ)
return q.subr(λʹ, p, e, a, Ω, i)
}
示例5: f
func f(x, y float64) float64 {
v := math.Pow(2.0, math.Sin(y)) * math.Pow(2.0, math.Sin(x)) / 12
if math.IsNaN(v) {
return 0
}
return v
}
示例6: Simulate
// Simulate executes the simulation steps in order to move the entity to it's
// new location and apply any pending updates/changes.
func (e *Entity) Simulate() {
var angleNot = e.Angle
var velocityNot = e.Velocity
// mark that we did what they thought we did
e.Updated = e.Updates
// apply YAW
if e.Updates.Left != e.Updates.Right {
if e.Updates.Left {
e.Angle -= angleStep
} else {
e.Angle += angleStep
}
}
// apply THRUST
if e.Updates.Forward != e.Updates.Backward {
if e.Updates.Forward {
e.Velocity.X += e.thrust * math.Cos(angleNot)
e.Velocity.Y += e.thrust * math.Sin(angleNot)
} else {
e.Velocity.X -= e.thrust * math.Cos(angleNot)
e.Velocity.Y -= e.thrust * math.Sin(angleNot)
}
}
// reset the updates to be performed
e.Updates = CommandUpdate{}
// update POSITION
e.Position.X += halfTimestep * (velocityNot.X + e.Velocity.X)
e.Position.Y += halfTimestep * (velocityNot.Y + e.Velocity.Y)
}
示例7: lissajous
func lissajous(out io.Writer) {
const (
cycles = 5 // number of complete x oscillator revolutions
res = 0.001 // angular resolution
size = 100 // image canvas covers [-size..+size]
nframes = 64 // number of animation frames
delay = 8 // delay between frames in 10ms units
)
freq := rand.Float64() * 3.0 // relative frequency of y oscillator
anim := gif.GIF{LoopCount: nframes}
phase := 0.0 // phase difference
for i := 0; i < nframes; i++ {
rect := image.Rect(0, 0, 2*size+1, 2*size+1)
img := image.NewPaletted(rect, palette)
index := uint8(rand.Int() % len(palette)) // random palette index color
if index == 0 {
index = 1 // change the index if the color is the same as the background color
}
for t := 0.0; t < cycles*2*math.Pi; t += res {
x := math.Sin(t)
y := math.Sin(t*freq + phase)
img.SetColorIndex(size+int(x*size+0.5), size+int(y*size+0.5), index)
}
phase += 0.1
anim.Delay = append(anim.Delay, delay)
anim.Image = append(anim.Image, img)
}
if err := gif.EncodeAll(out, &anim); err != nil {
log.Fatal(err)
}
}
示例8: lissajous
func lissajous(out io.Writer) {
const (
cycles = 5 // number of complete x oscillator revolutions
res = 0.001 // angular resolution
size = 100 // image canvas covers [-size..+size]
nframes = 64 // number of animation frames
delay = 8 // delay between frames in 10ms units
)
freq := rand.Float64() * 3.0 // relative frequency of y oscillator
// gif.GIF is a struct type. Somehow this allows the struct to be initialized with nframes,
// the rest are 0 due to some defaulting.
anim := gif.GIF{LoopCount: nframes}
phase := 0.0 // phase difference
for i := 0; i < nframes; i++ {
rect := image.Rect(0, 0, 2*size+1, 2*size+1)
img := image.NewPaletted(rect, palette)
for t := 0.0; t < cycles*2*math.Pi; t += res {
x := math.Sin(t)
y := math.Sin(t*freq + phase)
// BobK: I have no idea what int(x*size+0.5) is doing
img.SetColorIndex(size+int(x*size+0.5), size+int(y*size+0.5),
blackIndex)
}
phase += 0.1
anim.Delay = append(anim.Delay, delay)
anim.Image = append(anim.Image, img)
}
gif.EncodeAll(out, &anim) // NOTE: ignoring encoding errors
}
示例9: TrueCentroid
func TrueCentroid(a, b, c Point) interface{} {
angleA := b.Angle(c.Vector).Radians()
angleB := c.Angle(a.Vector).Radians()
angleC := a.Angle(b.Vector).Radians()
ra, rb, rc := 1., 1., 1.
if angleA != 0 {
ra = angleA / math.Sin(angleA)
}
if angleB != 0 {
rb = angleB / math.Sin(angleB)
}
if angleC != 0 {
rc = angleC / math.Sin(angleC)
}
x := r3.Vector{a.X, b.X - a.X, c.X - a.X}
y := r3.Vector{a.Y, b.Y - a.Y, c.Y - a.Y}
z := r3.Vector{a.Z, b.Z - a.Z, c.Z - a.Z}
r := r3.Vector{ra, rb - ra, rc - ra}
v := r3.Vector{
y.Cross(z).Dot(r),
z.Cross(x).Dot(r),
x.Cross(y).Dot(r),
}
return Point{v.Mul(0.5)}
}
示例10: ZeroTempF0AbsError
// 1/(t0+tz) = 1/N \sum_k (sin(kx) + alpha*sin(ky))^2 / E(k)
func ZeroTempF0AbsError(env Environment) float64 {
worker := func(k Vector2) float64 {
sinPart := math.Sin(k.X) + float64(env.Alpha)*math.Sin(k.Y)
return sinPart * sinPart / ZeroTempPairEnergy(env, k)
}
return 1/(env.T0+env.Tz) - Average(env.GridLength, worker)
}
示例11: z_triangulation
func z_triangulation(x int, y int, scan_number int) float64 {
y = image_size_y - y
var theta float64 = translate(float64(scan_number), 0.0, float64(frame_count-1), left_theta, right_theta)
var alpha float64 = translate(float64(scan_number), 0.0, float64(frame_count-1), left_alpha, right_alpha)
var z float64 = float64(b) * (math.Sin(theta) / math.Sin(alpha+theta))
return z * (-float64(f))
}
示例12: ZeroTempD1AbsError
// D1 = -1/(2N) \sum_k (1 - xi(k)/E(k)) * sin(kx) * sin(ky)
func ZeroTempD1AbsError(env Environment) float64 {
worker := func(k Vector2) float64 {
sx, sy := math.Sin(k.X), math.Sin(k.Y)
return -0.5 * (1 - Xi(env, k)/ZeroTempPairEnergy(env, k)) * sx * sy
}
return env.D1 - Average(env.GridLength, worker)
}
示例13: CartesianToPolar
// Convert Cartesian coordinates to polar.
// The reference ellipsoid is copied verbatim to the result.
// The resulting polar coordinates are in decimal degrees.
// Inspired by http://www.movable-type.co.uk/scripts/latlong-convert-coords.html
func CartesianToPolar(pt *CartPoint) *PolarCoord {
var gc PolarCoord
el := pt.El
esq := (el.a*el.a - el.b*el.b) / (el.a * el.a)
p := math.Hypot(pt.X, pt.Y)
lat := math.Atan2(pt.Z, p*(1-esq))
lat0 := 2.0 * math.Pi
precision := 4.0 / el.a
var v float64
for math.Abs(lat-lat0) > precision {
v = el.a / math.Sqrt(1-esq*math.Pow(math.Sin(lat), 2))
lat0 = lat
lat = math.Atan2(pt.Z+esq*v*math.Sin(lat), p)
}
gc.Height = p/math.Cos(lat) - v
gc.Latitude = radtodeg(lat)
gc.Longitude = radtodeg(math.Atan2(pt.Y, pt.X))
gc.El = el
return &gc
}
示例14: lissajous
func lissajous(out http.ResponseWriter, r *http.Request) {
const (
res = 0.001 // angular resolution
size = 500 // image canvas covers [-size..+size]
nframes = 64 // number of animation frames
delay = 8 // delay between frames in 10ms units
)
if err := r.ParseForm(); err != nil {
os.Exit(1)
}
for k, v := range r.Form {
fmt.Printf("%s:%s\n", k, v)
}
cyclesInt, _ := strconv.Atoi(r.Form.Get("cycles")) // number of complete x oscillator revolutions
cycles := float64(cyclesInt)
fmt.Printf("Float is: %f\n", cycles)
freq := rand.Float64() * 3.0 // relative frequency of y oscillator
anim := gif.GIF{LoopCount: nframes}
phase := 0.0 // phase difference
for i := 0; i < nframes; i++ {
rect := image.Rect(0, 0, 2*size+1, 2*size+1)
img := image.NewPaletted(rect, palette)
for t := 0.0; t < cycles*2*math.Pi; t += res {
x := math.Sin(t)
y := math.Sin(t*freq + phase)
img.SetColorIndex(size+int(x*size+0.5), size+int(y*size+0.5),
blackIndex)
}
phase += 0.1
anim.Delay = append(anim.Delay, delay)
anim.Image = append(anim.Image, img)
}
gif.EncodeAll(out, &anim) // NOTE: ignoring encoding errors
}
示例15: Writter
// Writter writes a Gif
// @param out a Writter
// @param cycles number of complete x oscillator revolutions
func Writter(out io.Writer, cycles float64) {
const (
res = 0.001 // angular resolution
size = 100 // image canvas covers [-size..+size]
nframes = 64 // number of animation frames
delay = 8 // delay between frames in 10ms units
)
freq := rand.Float64() * 12.0 // relative frequency of y oscillator
anim := gif.GIF{LoopCount: nframes}
phase := 0.0 // phase difference
for i := 0; i < nframes; i++ {
rect := image.Rect(0, 0, 2*size+1, 2*size+1)
img := image.NewPaletted(rect, pallete)
for t := 0.0; t < cycles*2*math.Pi; t += res {
x := math.Sin(t)
y := math.Sin(t*freq + phase)
if i%2 == 0 {
img.SetColorIndex(size+int(x*size+0.5), size+int(y*size+0.5), greenIndex)
} else {
img.SetColorIndex(size+int(x*size+0.5), size+int(y*size+0.5), blueIndex)
}
}
phase += 0.1
anim.Delay = append(anim.Delay, delay)
anim.Image = append(anim.Image, img)
}
gif.EncodeAll(out, &anim)
}