Ejemplo n.º 1
0
 def __init__(self, see: Horizontal, radius):
     self._see = see
     self._radius = radius
     self._radius_lb = cos(radians(self._radius))
     self._up_rotation = 0
     self._oyp = Horizontal(0, 0)
     self._update()
Ejemplo n.º 2
0
    def to_horizontal_with_latitude(self, h) -> Horizontal:
        f, t, d = map(math.radians, (h, *self))

        cosz = FirstEquatorialToHorizontal.cosz(f, d, t)
        sina_sinz = FirstEquatorialToHorizontal.siza_sinz(d, t)
        cosa_sinz = FirstEquatorialToHorizontal.cosa_sinz(f, d, t)

        if abs(cosz) > 1:
            cosz = 1 if cosz > 0 else -1
        sinz = math.sqrt(1 - cosz**2)
        if sinz == 0:
            return Horizontal(0, 90)
        sina = sina_sinz / sinz
        cosa = cosa_sinz / sinz
        a = atan2(sina, cosa)
        d = atan2(sinz, cosz)
        return Horizontal(*map(math.degrees, (a, math.pi / 2 - d)))
Ejemplo n.º 3
0
 def parse_str(s, regexp):
     match = regexp.match(s)
     if match is None:
         raise ValueError()
     groups = match.groupdict()
     if (not ("a" in groups)) or (not ("d" in groups)):
         raise ValueError()
     return Horizontal(float(groups["a"]), float(groups["d"]))
Ejemplo n.º 4
0
 def test_conversation(self, a, h):
     p = Horizontal(a, h).to_point()
     self.assertEqual(cos(radians(h)) * cos(radians(-a)),
                      p.x,
                      epsilon=self.EPS)
     self.assertEqual(cos(radians(h)) * sin(radians(-a)),
                      p.y,
                      epsilon=self.EPS)
     self.assertEqual(sin(radians(h)), p.z, epsilon=self.EPS)
Ejemplo n.º 5
0
 def test_cos_to(self, a0, h0, a1, h1):
     a = Horizontal(a0, h0)
     b = Horizontal(a1, h1)
     pa = a.to_point()
     pb = b.to_point()
     expected = -((pa - pb).length**2 - pa.length**2 - pb.length**2) / (
         2 * pa.length * pb.length)
     self.assertEqual(a.cos_to(b), expected, epsilon=self.EPS)
Ejemplo n.º 6
0
Archivo: task.py Proyecto: anaym/pysky
def create_task():
    args = parser.parse_args()
    dt = extract_time(args.d)
    if isinstance(dt, tuple):
        if args.d is not None:
            print('Bad datetime, use:\n\t{}\n\t{}\n\t{}'.format(
                *(str.join(', ', i) for i in dt)))
            sys.exit(1)
        else:
            dt = datetime.datetime.now()
    database = TxtDataBaseParser().parse(
        get_all_lines_in_dir(args.base, '.txt'))

    r = rset = Settings()
    if not args.disable_effects:
        r.fisheye, r.spectral, r.magnitude, = args.fisheye, args.spectral, args.magnitude
    else:
        r.fisheye, r.spectral, r.magnitude = False, False, False

    if not args.disable_points:
        r.see_points, r.screen_centre, r.compass = args.see_points, args.centre_direction, args.compass
    else:
        r.see_points, r.screen_centre, r.compass = False, False, False

    pos = BUILTIN_CITIES[args.city] if args.city else Horizontal(
        args.p[1], args.p[0])
    see = pos if args.see_up else Horizontal(*args.s)
    camera = Camera(see, 60)
    watcher = Watcher(pos, dt, camera)

    consts = args.constellations if args.constellations else database.constellations
    m_range = Range(min(*args.magnitude_range), max(*args.magnitude_range))
    selector = Filter(consts, m_range)

    return Task(database, selector, watcher, rset, args.out, args.music,
                args.console, args.full_screen, args.on_pause,
                not args.disable_animation)
Ejemplo n.º 7
0
 def _draw_point_and_direction(self, pos: Equatorial, color, size,
                               apply_latitude):
     self.settings.apply_color(color, self._painter)
     if apply_latitude:
         horizontal = pos.to_horizontal_with_latitude(
             self.watcher.position.h)
     elif isinstance(pos, Equatorial):
         horizontal = Horizontal(pos.a, pos.d)
     else:
         horizontal = pos
     p_lat = self.project_star(horizontal, Star(pos, '', size, '', ''),
                               True)
     if p_lat is not None and p_lat.in_eye:
         self._draw_object(p_lat, False)
     self._painter.drawLine(p_lat.cx, p_lat.cy, self.centre[0],
                            self.centre[1])
Ejemplo n.º 8
0
 def project_star(self,
                  pos: Horizontal,
                  star: Star,
                  always_project: bool = False):
     diameter = self._get_size(star.magnitude if star is not None else -1)
     in_eye = self.watcher.radius_low_bound < self.watcher.see.cos_to(
         pos) <= 1
     if in_eye or always_project:
         delta = pos.to_point() - self.watcher.see.to_point()
         prj_delta = delta.rmul_to_matrix(
             self.watcher.transformation_matrix)
         dx, dy = self.distortion(prj_delta.x, prj_delta.y,
                                  self.watcher.radius, prj_delta.z)
         diameter, _ = self.distortion(diameter, 0, self.watcher.radius,
                                       prj_delta.z)
         cx, cy = self.centre[0] + dx, self.centre[1] + dy
         return ProjectedStar(cx, cy, pos, diameter, star, in_eye)
Ejemplo n.º 9
0
Archivo: task.py Proyecto: anaym/pysky
import os
from argparse import ArgumentParser
import sys
import datetime
from collections import namedtuple
from os.path import join
from geometry.horizontal import Horizontal
from graphics.renderer.camera import Camera
from graphics.renderer.settings import Settings
from graphics.renderer.watcher import Watcher
from stars.filter import Filter
from stars.filter import Range
from stars.parser import TxtDataBaseParser

BUILTIN_CITIES = {"MGN": Horizontal(59, 53), "EKB": Horizontal(60, 56)}

parser = ArgumentParser(
    description="Sky visualizer",
    epilog="Developed by Anton Tolstov (aka Anaym): atolstov.com")

parser.add_argument('-c',
                    '--console',
                    action='store_true',
                    help="don`t use gui for visualization")
parser.add_argument('-m', '--music', action='store_true', help="enable music")
parser.add_argument('-b',
                    '--base',
                    type=str,
                    metavar='PATH',
                    default=join('stars', 'stars', 'txt'),
                    help="path to star date base")
Ejemplo n.º 10
0
 def _look_around(self, *delta):
     da, dh, dr = delta
     self.renderer.watcher.up_rotation += dr
     if abs(self.renderer.watcher.see.h + dh) > 90:
         return
     self.renderer.watcher.see += Horizontal(da, dh)
Ejemplo n.º 11
0
 def setUp(self):
     self.v = Horizontal(3, 4)
     self.a = Horizontal(1, 2)
Ejemplo n.º 12
0
 def see(self, value: Horizontal):
     self._see = Horizontal(value.a, value.h)
     self._update()
Ejemplo n.º 13
0
 def _update(self):
     self._oy = (self._see + Horizontal(self.up_rotation, -90))
     self._oyp = self._oy.to_point()
     self._ox_vector = self._see.to_point().vector_mul(self._oyp)
     self._transformation_matrix = [self._ox_vector, self._oyp, self._see.to_point()]