本文整理汇总了Golang中math.Asin函数的典型用法代码示例。如果您正苦于以下问题:Golang Asin函数的具体用法?Golang Asin怎么用?Golang Asin使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Asin函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TrueCentroid
/**
* Returns the true centroid of the spherical triangle ABC multiplied by the
* signed area of spherical triangle ABC. The reasons for multiplying by the
* signed area are (1) this is the quantity that needs to be summed to compute
* the centroid of a union or difference of triangles, and (2) it's actually
* easier to calculate this way.
*/
func TrueCentroid(a, b, c Point) Point {
// I couldn't find any references for computing the true centroid of a
// spherical triangle... I have a truly marvellous demonstration of this
// formula which this margin is too narrow to contain :)
// assert (isUnitLength(a) && isUnitLength(b) && isUnitLength(c));
sina := b.Cross(c.Vector).Norm()
sinb := c.Cross(a.Vector).Norm()
sinc := a.Cross(b.Vector).Norm()
var ra float64 = 1
var rb float64 = 1
var rc float64 = 1
if sina != 0 {
ra = math.Asin(sina) / sina
}
if sinb != 0 {
rb = math.Asin(sinb) / sinb
}
if sinc != 0 {
rc = math.Asin(sinc) / sinc
}
// Now compute a point M such that M.X = rX * det(ABC) / 2 for X in A,B,C.
x := PointFromCoordsRaw(a.X, b.X, c.X)
y := PointFromCoordsRaw(a.Y, b.Y, c.Y)
z := PointFromCoordsRaw(a.Z, b.Z, c.Z)
r := PointFromCoordsRaw(ra, rb, rc)
return PointFromCoordsRaw(
0.5*y.Cross(z.Vector).Dot(r.Vector),
0.5*z.Cross(x.Vector).Dot(r.Vector),
0.5*x.Cross(y.Vector).Dot(r.Vector),
)
}
示例2: DistanceToEdgeWithNormal
// This is named GetDistance() in the C++ API.
func (x Point) DistanceToEdgeWithNormal(a, b, a_cross_b Point) s1.Angle {
// There are three cases. If X is located in the spherical wedge
// defined by A, B, and the axis A x B, then the closest point is on
// the segment AB. Otherwise the closest point is either A or B; the
// dividing line between these two cases is the great circle passing
// through (A x B) and the midpoint of AB.
if CCW(a_cross_b, a, x) && CCW(x, b, a_cross_b) {
// The closest point to X lies on the segment AB. We compute
// the distance to the corresponding great circle. The result
// is accurate for small distances but not necessarily for
// large distances (approaching Pi/2).
//
// TODO: sanity check a != b
sin_dist := math.Abs(x.Dot(a_cross_b.Vector)) / a_cross_b.Norm()
return s1.Angle(math.Asin(math.Min(1.0, sin_dist)))
}
// Otherwise, the closest point is either A or B. The cheapest method is
// just to compute the minimum of the two linear (as opposed to spherical)
// distances and convert the result to an angle. Again, this method is
// accurate for small but not large distances (approaching Pi).
xa := x.Sub(a.Vector).Norm2()
xb := x.Sub(b.Vector).Norm2()
linear_dist2 := math.Min(xa, xb)
return s1.Angle(2 * math.Asin(math.Min(1.0, 0.5*math.Sqrt(linear_dist2))))
}
示例3: getDistanceWithCross
/**
* A slightly more efficient version of getDistance() where the cross product
* of the two endpoints has been precomputed. The cross product does not need
* to be normalized, but should be computed using S2.robustCrossProd() for the
* most accurate results.
*/
func getDistanceWithCross(x, a, b, aCrossB Point) s1.Angle {
if !x.IsUnit() || !a.IsUnit() || !b.IsUnit() {
panic("x, a and b need to be unit length")
}
// There are three cases. If X is located in the spherical wedge defined by
// A, B, and the axis A x B, then the closest point is on the segment AB.
// Otherwise the closest point is either A or B; the dividing line between
// these two cases is the great circle passing through (A x B) and the
// midpoint of AB.
if simpleCCW(aCrossB, a, x) && simpleCCW(x, b, aCrossB) {
// The closest point to X lies on the segment AB. We compute the distance
// to the corresponding great circle. The result is accurate for small
// distances but not necessarily for large distances (approaching Pi/2).
sinDist := math.Abs(x.Dot(aCrossB.Vector)) / aCrossB.Norm()
return s1.Angle(math.Asin(math.Min(1.0, sinDist)))
}
// Otherwise, the closest point is either A or B. The cheapest method is
// just to compute the minimum of the two linear (as opposed to spherical)
// distances and convert the result to an angle. Again, this method is
// accurate for small but not large distances (approaching Pi).
linearDist2 := math.Min(x.Sub(a.Vector).Norm2(), x.Sub(b.Vector).Norm2())
return s1.Angle(2 * math.Asin(math.Min(1.0, 0.5*math.Sqrt(linearDist2))))
}
示例4: getBoundingBox
func getBoundingBox(rf Radiusfence) (x1, x2, y1, y2 float64) {
var lat1, lat2, lon1, lon2 float64
//Convert long,lat to rad
latRad := rf.p.Latitude * DegToRad
longRad := rf.p.Longitude * DegToRad
northMost := math.Asin(math.Sin(latRad)*math.Cos(rf.r/Radius) + math.Cos(latRad)*math.Sin(rf.r/Radius)*math.Cos(North))
southMost := math.Asin(math.Sin(latRad)*math.Cos(rf.r/Radius) + math.Cos(latRad)*math.Sin(rf.r/Radius)*math.Cos(South))
eastMost := longRad + math.Atan2(math.Sin(East)*math.Sin(rf.r/Radius)*math.Cos(latRad), math.Cos(rf.r/Radius)-math.Sin(latRad)*math.Sin(latRad))
westMost := longRad + math.Atan2(math.Sin(West)*math.Sin(rf.r/Radius)*math.Cos(latRad), math.Cos(rf.r/Radius)-math.Sin(latRad)*math.Sin(latRad))
if northMost > southMost {
lat1 = southMost
lat2 = northMost
} else {
lat1 = northMost
lat2 = southMost
}
if eastMost > westMost {
lon1 = westMost
lon2 = eastMost
} else {
lon1 = eastMost
lon2 = westMost
}
return lat1, lat2, lon1, lon2
}
示例5: Grena3
// Grena3 calculates topocentric solar position following algorithm number 3
// described in Grena, 'Five new algorithms for the computation of sun position
// from 2010 to 2110', Solar Energy 86 (2012) pp. 1323-1337.
func Grena3(date time.Time,
latitudeDegrees float64, longitudeDegrees float64,
deltaTSeconds float64,
pressureHPa float64, temperatureCelsius float64) (azimuthDegrees, zenithDegrees float64) {
t := calcT(date)
tE := t + 1.1574e-5*deltaTSeconds
omegaAtE := 0.0172019715 * tE
lambda := -1.388803 + 1.720279216e-2*tE + 3.3366e-2*math.Sin(omegaAtE-0.06172) +
3.53e-4*math.Sin(2.0*omegaAtE-0.1163)
epsilon := 4.089567e-1 - 6.19e-9*tE
sLambda := math.Sin(lambda)
cLambda := math.Cos(lambda)
sEpsilon := math.Sin(epsilon)
cEpsilon := math.Sqrt(1.0 - sEpsilon*sEpsilon)
alpha := math.Atan2(sLambda*cEpsilon, cLambda)
if alpha < 0 {
alpha = alpha + 2*math.Pi
}
delta := math.Asin(sLambda * sEpsilon)
h := 1.7528311 + 6.300388099*t + toRad(longitudeDegrees) - alpha
h = math.Mod((h+math.Pi), (2*math.Pi)) - math.Pi
if h < -math.Pi {
h = h + 2*math.Pi
}
sPhi := math.Sin(toRad(latitudeDegrees))
cPhi := math.Sqrt((1 - sPhi*sPhi))
sDelta := math.Sin(delta)
cDelta := math.Sqrt(1 - sDelta*sDelta)
sH := math.Sin(h)
cH := math.Cos(h)
sEpsilon0 := sPhi*sDelta + cPhi*cDelta*cH
eP := math.Asin(sEpsilon0) - 4.26e-5*math.Sqrt(1.0-sEpsilon0*sEpsilon0)
gamma := math.Atan2(sH, cH*sPhi-sDelta*cPhi/cDelta)
deltaRe := 0.0
if eP > 0 && pressureHPa > 0.0 && pressureHPa < 3000.0 &&
temperatureCelsius > -273 && temperatureCelsius < 273 {
deltaRe = (0.08422 * (pressureHPa / 1000)) / ((273.0 + temperatureCelsius) *
math.Tan(eP+0.003138/(eP+0.08919)))
}
z := math.Pi/2 - eP - deltaRe
azimuthDegrees = convertAzimuth(gamma)
zenithDegrees = toDeg(z)
return
}
示例6: main
func main() {
fmt.Println("cos(pi/2):", math.Cos(math.Pi/2))
fmt.Println("cos(0):", math.Cos(0))
fmt.Println("sen(pi/2):", math.Sin(math.Pi/2))
fmt.Println("sen(0):", math.Sin(0))
fmt.Println("arccos(1):", math.Acos(1))
fmt.Println("arccos(0):", math.Acos(0))
fmt.Println("arcsen(1):", math.Asin(1))
fmt.Println("arcsen(0):", math.Asin(0))
}
示例7: TestDistanceToEdge
// Given a point X and an edge AB, check that the distance from X to AB is
// "distance_radians" and the closest point on AB is "expected_closest"
func TestDistanceToEdge(t *testing.T) {
tests := []struct {
x Point
a Point
b Point
distance_radians float64
expected_closest Point
}{
{pc(1, 0, 0), pc(1, 0, 0), pc(0, 1, 0), 0, pc(1, 0, 0)},
{pc(0, 1, 0), pc(1, 0, 0), pc(0, 1, 0), 0, pc(0, 1, 0)},
{pc(1, 3, 0), pc(1, 0, 0), pc(0, 1, 0), 0, pc(1, 3, 0)},
{pc(0, 0, 1), pc(1, 0, 0), pc(0, 1, 0), math.Pi / 2, pc(1, 0, 0)},
{pc(0, 0, -1), pc(1, 0, 0), pc(0, 1, 0), math.Pi / 2, pc(1, 0, 0)},
{pc(-1, -1, 0), pc(1, 0, 0), pc(0, 1, 0), 0.75 * math.Pi, pc(0, 0, 0)},
{pc(0, 1, 0), pc(1, 0, 0), pc(1, 1, 0), math.Pi / 4, pc(1, 1, 0)},
{pc(0, -1, 0), pc(1, 0, 0), pc(1, 1, 0), math.Pi / 2, pc(1, 0, 0)},
{pc(0, -1, 0), pc(1, 0, 0), pc(-1, 1, 0), math.Pi / 2, pc(1, 0, 0)},
{pc(-1, -1, 0), pc(1, 0, 0), pc(-1, 1, 0), math.Pi / 2, pc(-1, 1, 0)},
{pc(1, 1, 1), pc(1, 0, 0), pc(0, 1, 0), math.Asin(math.Sqrt(1. / 3)), pc(1, 1, 0)},
{pc(1, 1, -1), pc(1, 0, 0), pc(0, 1, 0), math.Asin(math.Sqrt(1. / 3)), pc(1, 1, 0)},
{pc(-1, 0, 0), pc(1, 1, 0), pc(1, 1, 0), 0.75 * math.Pi, pc(1, 1, 0)},
{pc(0, 0, -1), pc(1, 1, 0), pc(1, 1, 0), math.Pi / 2, pc(1, 1, 0)},
{pc(-1, 0, 0), pc(1, 0, 0), pc(1, 0, 0), math.Pi, pc(1, 0, 0)},
}
for _, test := range tests {
test.x = Point{test.x.Normalize()}
test.a = Point{test.a.Normalize()}
test.b = Point{test.b.Normalize()}
test.expected_closest = Point{test.expected_closest.Normalize()}
got := test.x.DistanceToEdge(test.a, test.b).Radians()
if math.Abs(got-test.distance_radians) > 1e-14 {
t.Errorf("%v.DistanceToEdge(%v, %v) = %v, want %v",
test.x, test.a, test.b, got, test.distance_radians)
}
closest := test.x.ClosestPoint(test.a, test.b)
if test.expected_closest == pc(0, 0, 0) {
if closest != test.a && closest != test.b {
t.Errorf("NOT: %v == %v || %v == %v", closest, test.a, closest, test.b)
}
} else {
if !closest.ApproxEqual(test.expected_closest) {
t.Errorf("%v != %v", closest, test.expected_closest)
}
}
}
}
示例8: Test_Mw02
func Test_Mw02(tst *testing.T) {
//verbose()
chk.PrintTitle("Mw02")
prms := []string{"φ", "Mfix"}
vals := []float64{32, 0}
var o NcteM
o.Init(prms, vals)
if SAVE_FIG {
// rosette
full, ref := false, true
r := 1.1 * SQ2 * o.M(1) / 3.0
PlotRosette(r, full, ref, true, 7)
// NcteM
npts := 201
X := make([]float64, npts)
Y := make([]float64, npts)
W := utl.LinSpace(-1, 1, npts)
for i, w := range W {
θ := math.Asin(w) / 3.0
r := SQ2 * o.M(w) / 3.0
X[i] = -r * math.Sin(math.Pi/6.0-θ)
Y[i] = r * math.Cos(math.Pi/6.0-θ)
//plt.Text(X[i], Y[i], io.Sf("$\\\\theta=%.2f$", θ*180.0/math.Pi), "size=8, ha='center', color='red'")
//plt.Text(X[i], Y[i], io.Sf("$w=%.2f$", w), "size=8, ha='center', color='red'")
}
plt.Plot(X, Y, "'b-'")
// MC
g := func(θ float64) float64 {
return SQ2 * o.Sinφ / (SQ3*math.Cos(θ) - o.Sinφ*math.Sin(θ))
}
io.Pforan("M( 1) = %v\n", SQ2*o.M(1)/3.0)
io.Pforan("g(30) = %v\n", g(math.Pi/6.0))
for i, w := range W {
θ := math.Asin(w) / 3.0
r := g(θ)
X[i] = -r * math.Sin(math.Pi/6.0-θ)
Y[i] = r * math.Cos(math.Pi/6.0-θ)
}
plt.Plot(X, Y, "'k-'")
// save
plt.Equal()
plt.SaveD("/tmp/gosl", "mw02.eps")
}
}
示例9: main
func main() {
fmt.Printf("sin(%9.6f deg) = %f\n", d, math.Sin(d*math.Pi/180))
fmt.Printf("sin(%9.6f rad) = %f\n", r, math.Sin(r))
fmt.Printf("cos(%9.6f deg) = %f\n", d, math.Cos(d*math.Pi/180))
fmt.Printf("cos(%9.6f rad) = %f\n", r, math.Cos(r))
fmt.Printf("tan(%9.6f deg) = %f\n", d, math.Tan(d*math.Pi/180))
fmt.Printf("tan(%9.6f rad) = %f\n", r, math.Tan(r))
fmt.Printf("asin(%f) = %9.6f deg\n", s, math.Asin(s)*180/math.Pi)
fmt.Printf("asin(%f) = %9.6f rad\n", s, math.Asin(s))
fmt.Printf("acos(%f) = %9.6f deg\n", c, math.Acos(c)*180/math.Pi)
fmt.Printf("acos(%f) = %9.6f rad\n", c, math.Acos(c))
fmt.Printf("atan(%f) = %9.6f deg\n", t, math.Atan(t)*180/math.Pi)
fmt.Printf("atan(%f) = %9.6f rad\n", t, math.Atan(t))
}
示例10: Dist
// Dist computes the spherical distance between two points on the unit sphere S².
func (p Geo) Dist(q Geo) float64 {
u1 := p.c()
v1 := q.c()
dot := u1.dot(v1)
if dot > 0 {
t := u1.sub(v1)
return 2 * math.Asin(0.5*t.abs())
}
if dot < 0 {
t := u1.add(v1)
return math.Pi - 2*math.Asin(0.5*t.abs())
}
return math.Pi / 2
}
示例11: geoBoundAroundPoint
func geoBoundAroundPoint(center *Point, distance float64) *Bound {
radDist := distance / EarthRadius
radLat := deg2rad(center.Lat())
radLon := deg2rad(center.Lng())
minLat := radLat - radDist
maxLat := radLat + radDist
var minLon, maxLon float64
if minLat > minLatitude && maxLat < maxLatitude {
deltaLon := math.Asin(math.Sin(radDist) / math.Cos(radLat))
minLon = radLon - deltaLon
if minLon < minLongitude {
minLon += 2 * math.Pi
}
maxLon = radLon + deltaLon
if maxLon > maxLongitude {
maxLon -= 2 * math.Pi
}
} else {
minLat = math.Max(minLat, minLatitude)
maxLat = math.Min(maxLat, maxLatitude)
minLon = minLongitude
maxLon = maxLongitude
}
return &Bound{
sw: &Point{rad2deg(minLon), rad2deg(minLat)},
ne: &Point{rad2deg(maxLon), rad2deg(maxLat)},
}
}
示例12: sep
// u.sep(v) returns ∠(u,v) (angular separation).
func (u vec) sep(v vec) float64 {
u1, v1 := u.hat(), v.hat()
dot := u1.dot(v1)
if dot > 0 {
t := u1.sub(v1)
return 2 * math.Asin(0.5*t.abs())
}
if dot < 0 {
t := u1.add(v1)
return math.Pi - 2*math.Asin(0.5*t.abs())
}
if u1.maxabs() == 0 || v1.maxabs() == 0 {
return 0
}
return math.Pi / 2
}
示例13: ElasticInOut
// ElasticInOut Acceleration until halfway, then deceleration
func ElasticInOut(t, b, c, d float64) float64 {
if t > d {
return c
}
s := math.SqrtPi
p := d * (0.3 * 1.5)
a := c
if t == 0 {
return b
}
t /= d / 2
if t == 2 {
return b + c
}
if a < math.Abs(c) {
s = p / 4
} else {
s = p / DoublePi * math.Asin(c/a)
}
t--
if t < 0 {
return -0.5*(a*math.Pow(2, 10*t)*math.Sin((t*d-s)*DoublePi/p)) + b
}
return a*math.Pow(2, -10*t)*math.Sin((t*d-s)*DoublePi/p)*0.5 + c + b
}
示例14: ElasticOut
// ElasticOut Decelerating to zero velocity
func ElasticOut(t, b, c, d float64) float64 {
if t > d {
return c
}
s := math.SqrtPi
p := d * 0.3
a := c
if t == 0 {
return b
}
t /= d
if t == 1 {
return b + c
}
if a < math.Abs(c) {
s = p / 4
} else {
s = p / DoublePi * math.Asin(c/a)
}
return a*math.Pow(2, -10*t)*math.Sin((t*d-s)*DoublePi/p) + c + b
}
示例15: 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}},
}
}