Got huge error on Skyfield test the 2-stars fix math

Am trying to do a simple test of 2-stars fix math with Skyfield python lib and Celestial Programming site at https://www.celestialprogramming.com/snippets/twoStarFix.html
So I’m getting the data of imagined observation about a 2 stars from Hipparcos using Skyfield for some geographic position at a time t. Then I’m calculating back the geographic position of observer using the math from Celestial Programming site. And I’m getting a big error, eg.:

in data: 49N, 25E
result: 48.966578719047284, 25.25305554808433

Where is the problem? Is there an error in code somewhere? Thanks for help!

The code itself:

# Greg Miller ([email protected]) 2023 http://www.celestialprogramming.com/

from skyfield.api import Topos, N, E, W, wgs84, load, Star
from skyfield.data import hipparcos
from skyfield.positionlib import position_of_radec
from math import pi, sin, cos, acos, atan2, sqrt

rad = pi/180.0

# Angles returned in radians
def rectToPolar(x, y, z):
    r = sqrt(x * x + y * y + z * z);
    lon = atan2(y, x);
    lat = acos(z / r);
    lat = pi/2 - lat # Make sure lat is in range +/-90deg
    return [lat, lon, r]

# star[0]=GP Longitude, star[1]=Declination, star[2]=Zenith Distance
def sightReduce(star1, star2):
    # From "An Analytical Solution of the Two Star Sight Problem of Celestial Navigation." 
    # James A. Van Allen

    a1 = cos(star1[0])*cos(star1[1])
    a2 = cos(star2[0])*cos(star2[1])

    b1=sin(star1[0])*cos(star1[1])
    b2=sin(star2[0])*cos(star2[1])

    c1=sin(star1[1])
    c2=sin(star2[1])

    p1=cos(star1[2])
    p2=cos(star2[2])

    # Eq 3
    A=a1*b2 - a2*b1
    B=b2*c1 - b1*c2
    C=b2*p1 - b1*p2
    D=a1*c2 - a2*c1
    E=b1*c2 - b2*c1
    F=c2*p1 - c1*p2

    # Eq 4 substituded in to eq 5
    # x^2(1+A^2/B^2 + D^2/E^2) + x(-2AC/B^2 - 2FD/E^2) + C^2/B^2 + F^2/E^2 - 1

    # Quadratic solve
    a=(1+(A*A)/(B*B)+(D*D)/(E*E))
    b=((-2*A*C)/(B*B) - (2*F*D)/(E*E))
    c=(C*C)/(B*B) + (F*F)/(E*E) - 1

    x1=(-b+sqrt(b*b - 4*a*c))/(2*a)
    x2=(-b-sqrt(b*b - 4*a*c))/(2*a)

    # eq  4
    y1=(F-D*x1)/E
    y2=(F-D*x2)/E

    z1=(C-A*x1)/B
    z2=(C-A*x2)/B

    s1=rectToPolar(x1,y1,z1)
    s2=rectToPolar(x2,y2,z2)

    return [s1[0]/rad, s1[1]/rad, s2[0]/rad, s2[1]/rad]

with load.open(hipparcos.URL) as f:
    df = hipparcos.load_dataframe(f)
planets = load('de421.bsp') # Load the JPL ephemeris DE421 (covers 1900-2050).
earth = planets['earth']

origLat, origLng = 49, 25

(txtLat, txtLatS) = (-origLat, "S") if (origLat < 0) else (origLat, "N")
(txtLng, txtLngS) = (-origLng, "W") if (origLng < 0) else (origLng, "E")
te = Topos(str(txtLat)+" "+txtLatS, str(txtLng)+" "+txtLngS)# elevation_m=300

tx = 1710621420+27
t = load.timescale().utc(1970, 1, 1, 0, 0, tx)
print(t.utc_strftime())
body = [4427, 67301]

def getHip(body):
    star = Star.from_dataframe(df.loc[body])
    pps = (earth + te).at(t).observe(star).apparent()
    alt0, az0, distance = pps.altaz()
    pps = (earth).at(t).observe(star)
    ra0, dec0, distance = pps.radec('date')
    xppq = position_of_radec(ra0.radians*12/pi, dec0.radians*180/pi, t=t, center=399)
    xq2 = wgs84.geographic_position_of(xppq)
    return [xq2.longitude.radians, dec0.radians, pi/2-alt0.radians] # [0]=GP Longitude, [1]=Declination, [2]=Zenith Distance

print(origLat, origLng)
print(sightReduce(getHip(body[0]), getHip(body[1])))

Have tried this python code example and got a big error.

New contributor

Тютюник Валентина is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

1

It sounds like you encountered a significant error while testing the math for a two-star fix in Skyfield. When working with celestial navigation or similar applications, accuracy is crucial. Here’s how you can approach resolving this issue:

  1. Check Input Data: Ensure that the input data you provided to Skyfield is accurate. This includes the coordinates of the stars or celestial bodies, the time of observation, and any other relevant parameters.

  2. Review Code Logic: Double-check the code logic you used for calculating the two-star fix in Skyfield. Look for any potential mistakes or inaccuracies in the mathematical calculations or algorithms.

  3. Compare Results: Compare the results obtained from Skyfield with known values or results from other sources. This can help identify discrepancies and pinpoint the source of the error.

  4. Debugging: Use debugging techniques to step through the code and track the values of variables at each step of the calculation. This can help you identify where the error occurs and why.

  5. Consult Documentation: Refer to the documentation and resources provided by Skyfield to understand how the two-star fix calculation should be implemented correctly. Pay attention to any specific requirements or considerations mentioned.

  6. Seek Community Support: If you’re still unable to resolve the error, consider reaching out to the Skyfield community or forums for assistance. Other users or developers may have encountered similar issues and can offer valuable insights or solutions.

  7. Report Bugs: If you believe you’ve identified a bug in Skyfield, consider reporting it to the developers. Provide detailed information about the error you encountered, including any relevant code snippets, input data, and expected versus actual results.

By following these steps and carefully reviewing your code and calculations, you should be able to address the error in the two-star fix math in Skyfield and achieve accurate results.

New contributor

Harry T is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật