Class: When::Ephemeris::Coords

Inherits:
Object
  • Object
show all
Includes:
When::Ephemeris
Defined in:
lib/when_exe/ephemeris.rb

Overview

天体の座標

Constant Summary

Constants included from When::Ephemeris

AU, AcS, BCENT, C0, CIRCLE, COS, COSL, COSLT, COST, DAY, DEG, EPOCH1800, EPOCH1900, EPOCH1975, EPOCH2000, FARAWAY, JCENT, JYEAR, Jupiter, LIN, Mars, Mercury, Neptune, P0B, P0L, P0P, P0dB, P0dL, P1B, P1L, P1R, P2B, P2L, P2Q, P2dL, P3L, P3Q, P4B, P4L, P4Q, P4dL, P5B, P5L, P5Q, P5dL, P5l, P5n, P5r, P5t, P6B, P6L, P6Q, P6dL, P6l, P6n, P6r, P6t, P7B, P7L, P7R, P8B, P8L, P8R, P9B, P9L, P9R, PSEC, Pluto, SIN, SINL, SINLT, SINT, Saturn, Uranus, Venus

Class Method Summary collapse

Instance Method Summary collapse

Methods included from When::Ephemeris

_adjust, _rot, _to_p2, _to_p3, _to_r3, acos, asin, cosc, cosd, delta_e, delta_p, julian_century_from_2000, julian_year_from_1975, obl, polynomial, root, sinc, sind, tanc, tand, trigonometric

Constructor Details

#initialize(x, y, z, options = { :system=>:rectangular }) ⇒ Coords #initialize(phi, theta, radius, c, options = {}) ⇒ Coords

Note:

c - 周回数(デフォルト - phi から生成) z軸の周りを何週して現在の位置にあるかを保持する

オブジェクトの生成

Overloads:

  • #initialize(x, y, z, options = { :system=>:rectangular }) ⇒ Coords

    引数パターン 1

    Parameters:

    • x (Numeric)

      x 座標

    • y (Numeric)

      y 座標

    • z (Numeric)

      z 座標

    • options (Hash) (defaults to: { :system=>:rectangular })

      { :system=>:rectangular }

  • #initialize(phi, theta, radius, c, options = {}) ⇒ Coords

    Parameters:

    • phi (Numeric)

      経度 / CIRCLE

    • theta (Numeric)

      緯度 / CIRCLE

    • radius (Numeric)

      距離

    • c (Numeric)

      周回数

    • options (Hash) (defaults to: {})

      { :system=>:rectangular以外 }



723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
# File 'lib/when_exe/ephemeris.rb', line 723

def initialize(*args)
  @options = args[-1].kind_of?(Hash) ? args.pop.dup : {}
  if @options[:system] == :rectangular
    @x, @y, @z, @c = args
    @x  ||= 0.0  # X座標
    @y  ||= 0.0  # Y座標
    @z  ||= 0.0  # Z座標
  else
    @phi, @theta, @radius, @c = args
    @phi    ||=  0.0  # 経度
    @theta  ||=  0.0  # 緯度
    @radius ||=  1.0  # 距離
    @c      ||=  @phi # 周期番号
    @phi     -= (@phi - @c).round
  end
end

Class Method Details

.rectangular(x, y, z, c = nil) ⇒ When::Ephemeris::Coords

オブジェクトの生成

Parameters:

  • x (Numeric)

    x 座標

  • y (Numeric)

    y 座標

  • z (Numeric)

    z 座標

  • c (Numeric) (defaults to: nil)

    周回数(デフォルト - phi から生成)

    極座標との1対1対応を保証するため、z軸の周りを何週して 現在の位置にあるかを保持する

Returns:



371
372
373
# File 'lib/when_exe/ephemeris.rb', line 371

def rectangular(x, y, z, c=nil)
  Coords.new(x, y, z, c, {:system=>:rectangular})
end

Instance Method Details

#+(other) ⇒ When::Ephemeris::Coords

加法

Parameters:

Returns:

Raises:

  • (TypeError)


461
462
463
464
# File 'lib/when_exe/ephemeris.rb', line 461

def +(other)
  raise TypeError, 'operand should be When::Ephemeris::Coords' unless other.kind_of?(Coords)
  self.class.rectangular(x+other.x, y+other.y, z+other.z, c+other.c)
end

#-(other) ⇒ When::Ephemeris::Coords

減法

Parameters:

Returns:

Raises:

  • (TypeError)


472
473
474
475
# File 'lib/when_exe/ephemeris.rb', line 472

def -(other)
  raise TypeError, 'operand should be When::Ephemeris::Coords' unless other.kind_of?(Coords)
  self.class.rectangular(x-other.x, y-other.y, z-other.z, c-other.c)
end

#-@When::Ephemeris::Coords

点対称の反転



481
482
483
# File 'lib/when_exe/ephemeris.rb', line 481

def -@
  self.class.polar(phi+0.5, -theta, radius, c)
end

#[](z) ⇒ Numeric

要素参照

Parameters:

  • z (String, Symbol)

    要素名(‘x’, ‘y’, ‘z’, ‘phi’, ‘theta’, ‘r’, ‘c’, :x, :y, :z, :phi, :theta, :r, :c)

Returns:



451
452
453
# File 'lib/when_exe/ephemeris.rb', line 451

def [](z)
  send(z.to_sym)
end

#cNumeric

周回数

Returns:



443
# File 'lib/when_exe/ephemeris.rb', line 443

def c  ; @c  || polar[3] ; end

#cos_pes(planet) ⇒ Numeric

地球から見た惑星と太陽の視距離の余弦 - cosine of angle Planet - Earth - Sun

Parameters:

Returns:



680
681
682
# File 'lib/when_exe/ephemeris.rb', line 680

def cos_pes(planet)
  spherical_law_of_cosines(self - planet)
end

#cos_spe(planet) ⇒ Numeric

惑星から見た太陽と地球の視距離の余弦(惑星の満ち具合) - cosine of angle Sun - Planet - Earth

Parameters:

Returns:



690
691
692
# File 'lib/when_exe/ephemeris.rb', line 690

def cos_spe(planet)
  planet.spherical_law_of_cosines(planet - self)
end

#luminosity_spe(planet) ⇒ Numeric

惑星の明るさ - luminosity used cosine of angle Sun - Planet - Earth

Parameters:

Returns:



700
701
702
703
# File 'lib/when_exe/ephemeris.rb', line 700

def luminosity_spe(planet)
  difference = planet - self
  (planet.spherical_law_of_cosines(difference) + 1) / ( 2 * planet.radius * planet.radius * difference.radius * difference.radius)
end

#nutation(c) ⇒ When::Ephemeris::Coords

章動

Parameters:

  • c (Numeric)

    2000年からの経過世紀

Returns:



526
527
528
# File 'lib/when_exe/ephemeris.rb', line 526

def nutation(c)
  rotate_z(delta_p(c)).rotate_x(delta_e(c))
end

#parallax(t, loc) ⇒ When::Ephemeris::Coords

地心視差 (黄道座標) / 地心位置 -> 測心位置(観測地中心位置)

Parameters:

Returns:



575
576
577
578
# File 'lib/when_exe/ephemeris.rb', line 575

def parallax(t, loc)
  return self if loc.alt==When::Coordinates::Spatial::Center
  self - loc.coords_diff(t)
end

#phiNumeric

経度 / CIRCLE

Returns:



425
# File 'lib/when_exe/ephemeris.rb', line 425

def phi ; @phi || polar[0] ; end

#polarArray<Numeric>

極座標

Returns:

  • (Array<Numeric>)

    ( phi, theta, radius, c )

    phi - 経度 / CIRCLE
    theta - 緯度 / CIRCLE
    radius - 距離
    c - 周回数


414
415
416
417
418
419
# File 'lib/when_exe/ephemeris.rb', line 414

def polar
  @phi, @theta, @radius = _to_p3(@x, @y, @z) unless @radius
  @c ||=  @phi
  @phi -= (@phi - @c).round
  return [@phi, @theta, @radius, @c]
end

#precession(dt, t0) ⇒ When::Ephemeris::Coords

歳差

Parameters:

  • dt (Numeric)

    分点からの経過時間 / ベッセル世紀

  • t0 (Numeric)

    分点 / ベッセル世紀

Returns:



538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
# File 'lib/when_exe/ephemeris.rb', line 538

def precession(dt, t0)
  return self if (theta.abs>=0.25)

  b0 = dt / (360 * 3600.0)
  b1 = [+0.302, +0.018]
  b2 = [+0.791, +0.001]
  b3 = [-0.462, -0.042]

  b1.unshift(2304.250 + 1.396 * t0)
  b2.unshift(polynomial(dt, b1))
  b3.unshift(2004.682 - 0.853 * t0)

  z0 = b0 * b2[0]
  zt = b0 * polynomial(dt, b2)
  th = b0 * polynomial(dt, b3)

  a  = phi + z0
  b  = th / 2
  cA = cosc(a)
  sA = sinc(a)
  tB = tanc(b)
  q  = sinc(th)*(tanc(theta) + tB*cA)

  dRA = atan2(q*sA, 1-q*cA) / CIRCLE
  dDC = atan2(tB*(cA-sA*tanc(dRA/2)), 1) / CIRCLE

  self.class.polar(phi + dRA + z0 + zt, theta + 2*dDC, radius, @c)
end

#r_to_h(t, loc) ⇒ When::Ephemeris::Coords

赤道座標 -> 地平座標

Parameters:

Returns:



653
654
655
656
# File 'lib/when_exe/ephemeris.rb', line 653

def r_to_h(t, loc)
  rotate_z(-loc.local_sidereal_time(t) / 24).
  rotate_y(loc.lat / (360.0*When::Coordinates::Spatial::DEGREE) - 0.25)
end

#r_to_rh(t, loc) ⇒ When::Ephemeris::Coords

赤道座標 -> 赤道座標

Parameters:

Returns:



629
630
631
# File 'lib/when_exe/ephemeris.rb', line 629

def r_to_rh(t, loc)
  rotate_z(-loc.local_sidereal_time(t) / 24)
end

#r_to_y(t, loc = nil) ⇒ When::Ephemeris::Coords

赤道座標 -> 黄道座標

Parameters:

Returns:



588
589
590
591
592
593
594
595
596
597
598
599
600
# File 'lib/when_exe/ephemeris.rb', line 588

def r_to_y(t, loc=nil)
  t   = +t
  loc = loc.datum unless loc.kind_of?(Datum)
  n   = loc.axis_of_rotation(t) if loc
  if (n)
    c = rotate_z(+0.25 - n.radius).
        rotate_y(+0.25 - n.theta).
        rotate_z(+n.phi)
  else
    c = self
  end
  return c.rotate_x(-obl(julian_century_from_2000(t)))
end

#radiusNumeric

距離

Returns:



437
# File 'lib/when_exe/ephemeris.rb', line 437

def radius ; @radius || polar[2] ; end

#rectangularArray<Numeric>

直交座標

Returns:

  • (Array<Numeric>)

    ( x, y, z )

    x - x 座標
    y - y 座標
    z - z 座標


383
384
385
386
# File 'lib/when_exe/ephemeris.rb', line 383

def rectangular
  @x, @y, @z = _to_r3(@phi, @theta, @radius) unless @z
  return [@x, @y, @z]
end

#rh_to_h(t, loc) ⇒ When::Ephemeris::Coords

赤道座標 -> 地平座標

Parameters:

Returns:



641
642
643
# File 'lib/when_exe/ephemeris.rb', line 641

def rh_to_h(t, loc)
  rotate_y(loc.lat / (360.0*When::Coordinates::Spatial::DEGREE) - 0.25)
end

#rotate_x(t) ⇒ When::Ephemeris::Coords

X 軸を軸とする回転

Parameters:

  • t (Numeric)

    回転角 / CIRCLE

Returns:



491
492
493
494
495
# File 'lib/when_exe/ephemeris.rb', line 491

def rotate_x(t)
  cos = cosc(t)
  sin = sinc(t)
  self.class.rectangular(x, y*cos-z*sin, y*sin+z*cos, c)
end

#rotate_y(t) ⇒ When::Ephemeris::Coords

Y 軸を軸とする回転

Parameters:

  • t (Numeric)

    回転角 / CIRCLE

Returns:



503
504
505
506
507
# File 'lib/when_exe/ephemeris.rb', line 503

def rotate_y(t)
  cos = cosc(t)
  sin = sinc(t)
  self.class.rectangular(z*sin+x*cos, y, z*cos-x*sin, c)
end

#rotate_z(t) ⇒ When::Ephemeris::Coords

Z 軸を軸とする回転

Parameters:

  • t (Numeric)

    回転角 / CIRCLE

Returns:



515
516
517
# File 'lib/when_exe/ephemeris.rb', line 515

def rotate_z(t)
  self.class.polar(phi+t, theta, radius, c+t)
end

#spherical_law_of_cosines(other) ⇒ Numeric Also known as: cos_esp

球面の余弦 spherical law of cosines

Parameters:

Returns:



664
665
666
# File 'lib/when_exe/ephemeris.rb', line 664

def spherical_law_of_cosines(other)
  sinc(theta)*sinc(other.theta) + cosc(theta)*cosc(other.theta)*cosc(phi-other.phi)
end

#thetaNumeric

緯度 / CIRCLE

Returns:



431
# File 'lib/when_exe/ephemeris.rb', line 431

def theta ; @theta || polar[1] ; end

#xNumeric

x 座標

Returns:



392
# File 'lib/when_exe/ephemeris.rb', line 392

def x ; @x || rectangular[0] ; end

#yNumeric

y 座標

Returns:



398
# File 'lib/when_exe/ephemeris.rb', line 398

def y ; @y || rectangular[1] ; end

#y_to_r(t, loc = nil) ⇒ When::Ephemeris::Coords

黄道座標 -> 赤道座標

Parameters:

Returns:



610
611
612
613
614
615
616
617
618
619
# File 'lib/when_exe/ephemeris.rb', line 610

def y_to_r(t, loc=nil)
  t   = +t
  c   = rotate_x(+obl(julian_century_from_2000(t)))
  loc = loc.datum unless loc.kind_of?(Datum)
  n   = loc.axis_of_rotation(t) if loc
  return c unless n
  c.rotate_z(-n.phi).
    rotate_y(-0.25 + n.theta).
    rotate_z(-0.25 + n.radius)
end

#zNumeric

z 座標

Returns:



404
# File 'lib/when_exe/ephemeris.rb', line 404

def z ; @z || rectangular[2] ; end