-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
cmplx.go
64 lines (51 loc) · 1.39 KB
/
cmplx.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package gfx
import (
"image/color"
"math/cmplx"
)
// CmplxSin returns the sine of x.
func CmplxSin(x complex128) complex128 {
return cmplx.Sin(x)
}
// CmplxSinh returns the hyperbolic sine of x.
func CmplxSinh(x complex128) complex128 {
return cmplx.Sinh(x)
}
// CmplxCos returns the cosine of x.
func CmplxCos(x complex128) complex128 {
return cmplx.Cos(x)
}
// CmplxCosh returns the hyperbolic cosine of x.
func CmplxCosh(x complex128) complex128 {
return cmplx.Cosh(x)
}
// CmplxTan returns the tangent of x.
func CmplxTan(x complex128) complex128 {
return cmplx.Tan(x)
}
// CmplxTanh returns the hyperbolic tangent of x.
func CmplxTanh(x complex128) complex128 {
return cmplx.Tanh(x)
}
// CmplxPow returns x**y, the base-x exponential of y.
func CmplxPow(x, y complex128) complex128 {
return cmplx.Pow(x, y)
}
// CmplxSqrt returns the square root of x.
// The result r is chosen so that real(r) ≥ 0 and imag(r) has the same sign as imag(x).
func CmplxSqrt(x complex128) complex128 {
return cmplx.Sqrt(x)
}
// CmplxPhase returns the phase (also called the argument) of x.
// The returned value is in the range [-Pi, Pi].
func CmplxPhase(x complex128) float64 {
return cmplx.Phase(x)
}
// CmplxPhaseAt returns the color at the phase of the given complex128 value.
func (p Palette) CmplxPhaseAt(z complex128) color.Color {
t := CmplxPhase(z)/Pi + 1
if t > 1 {
t = 2 - t
}
return p.At(t)
}