sfcalcsheet icon indicating copy to clipboard operation
sfcalcsheet copied to clipboard

Equatorial to Galactic and Trig calc PLS

Open ARGHouse opened this issue 3 years ago • 5 comments
trafficstars

I'm working on 3D starmaps in Astrosynth and Pioneer, I usually have to go through around 5 to 10 minutes hopping between my calculator and various online calculators and converters so I can convert Equatorial in to Galactic, and then calculate the trigonomic values so I can get cartesian co-ordinates. Would be handy if this calculator also had an Equatorial to Galactic converter, along with a right angle trig calculator for getting cartesian co-ordinates.

ARGHouse avatar Oct 21 '22 05:10 ARGHouse

And by Equatorial coordinates you mean with respect to equator of Earth, or also equator of some other planets?

jchylik avatar Oct 31 '22 22:10 jchylik

Yep in respect to Earth, RA and Dec.

ARGHouse avatar Oct 31 '22 22:10 ARGHouse

This is in respect to the equator of Earth. I already found some formulas: Conversion of coordinates . Also see Google search "equatorial to galactic coordinates formula".

Such a calculator should be doable in SFCalcsheet, although I am a bit weak with trigonometry.

lortordermur avatar Oct 31 '22 22:10 lortordermur

Such a calculator should be doable in SFCalcsheet

It is definitely doable, but the tricky thing is checking in the excel sheet whether the input angle is in degrees or radians.

jchylik avatar Oct 31 '22 22:10 jchylik

I would standardize on degrees and include a degree <-> radian converter on the "Conversion" sheet.

lortordermur avatar Oct 31 '22 23:10 lortordermur

I am in the process of finally implementing the calculator but my math skills are not that great in the trigonometry and equations areas. After some tinkering I got the formula for galactic latitude right and the result is correct^1, however I still don't manage to solve for galactic longitude.

I tried most of the formulas from those sites:^2^4 The main matter is that I don't know how to solve for l in the left side of the equation (l - l0).

Here is a work-in-progress copy of the spreadsheet with the interim results visible: sfcalcsheet.ods

The versions of the galactic longitude formula are in cells G47-G49 and H49-J49. Maybe someone with better math skills can have a look at it.

lortordermur avatar Aug 14 '24 16:08 lortordermur

The main matter is that I don't know how to solve for l in the left side of the equation (l - l0).

If you mean the equation 10 (section "3.4.2. Transformation"), then it is pretty straightforward. The functions arcsin and arccos are both available in majority of Spreadsheets.

For example in Libre Office it is: =ASIN( * ) =ACOS( * )

jchylik avatar Aug 14 '24 16:08 jchylik

It is 3.2.1 but the principle is the same.

Yes, I already use ARCSIN/ARCCOS as the inverse operation before I convert to degrees. The issue is the l - l0 part on the left side of the equals sign in the second and third formula. So far I just add l0 at the end of the calculation but that doesn't seem to be the correct approach to just have l on the left side, i.e. eliminate the l0.

lortordermur avatar Aug 14 '24 17:08 lortordermur

The versions of the galactic longitude formula are in cells G47-G49 and H49-J49.

Please, on which sheet is it? I am having a difficulty to find it.

jchylik avatar Aug 14 '24 17:08 jchylik

It is on "Conversion", the purple one. Fifth calculator from the top.

lortordermur avatar Aug 14 '24 17:08 lortordermur

It is on "Conversion", the purple one. Fifth calculator from the top.

I have freshly downloaded the latest version, but it does not appear there. The fifth calculator is still Degrees <-> Radians

jchylik avatar Aug 14 '24 17:08 jchylik

I linked a work copy of the sheet in a previous issue comment.

https://github.com/lortordermur/sfcalcsheet/issues/5#issuecomment-2289237342

lortordermur avatar Aug 14 '24 17:08 lortordermur

I see.

There are a couple of typos, the first one I can see is:

G47 was missing "RADIANS"

=DEGREES(ACOS(COS(G46 - G45) * COS(H46) / COS(H47)) + I45)

=DEGREES(ACOS(COS(G46 - G45) * COS(H46) / COS(RADIANS(H47))) + I45)

I will have a deeper look at it and write more.

jchylik avatar Aug 14 '24 18:08 jchylik

Great, if we get the math figured out and the calculator can be implemented I can give you credit in the README if you like.

lortordermur avatar Aug 14 '24 19:08 lortordermur

I got it solved by correcting the formula in J49 (which I had generated using an online solver) to have the H47 value in radians and then converting everything to degrees.

Now working on the reverse calculator. From what I have read that should be doable by keeping the formulas and swapping a few variables around.

Thank you for taking the time to help out. Can I mention you in an acknowledgements section in the README?

lortordermur avatar Aug 15 '24 14:08 lortordermur

@ARGHouse: The converter between equatorial and galactic coordinates is now complete and in the git repo. Any feedback? And how would the calculator for cartesian coordinates work? Do you mean something that makes a vector from RA, Dec and distance and calculates a resulting point in space?

lortordermur avatar Aug 15 '24 17:08 lortordermur

I'll try it out, thanks.

On Fri, 16 Aug 2024, 3:50 am lortordermur, @.***> wrote:

@ARGHouse https://github.com/ARGHouse: The converter between equatorial and galactic coordinates is now complete and in the git repo. Any feedback? And how would the calculator for cartesian coordinates work? Do you mean something that makes a vector from RA, Dec and distance and calculates a resulting point in space?

— Reply to this email directly, view it on GitHub https://github.com/lortordermur/sfcalcsheet/issues/5#issuecomment-2291849526, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIH42YJ2SNCP5JJSPRVRBZ3ZRTS4XAVCNFSM6AAAAABMQV5F6OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOJRHA2DSNJSGY . You are receiving this because you were mentioned.Message ID: @.***>

ARGHouse avatar Aug 15 '24 22:08 ARGHouse

The converter between equatorial and galactic coordinates is now complete and in the git repo. Any feedback?

I have had a look at it, it works majority of angles, but there is an issue with ((galactic -> equatorial)) for some values on the opposite site of the circle. For example:

b l alpha delta
0. 212. 282.43 0.82
0. 213. 102.89 -0.06

I think it is either due to bounds of used functions, or some typo. I will have a closer look at it.

Can I mention you in an acknowledgements section in the README?

You can wait with mentioning me until I add the promised calculation of radiation effects on the atmosphere.

jchylik avatar Aug 16 '24 11:08 jchylik

Okay. For easier debugging you can make the hidden calculations visible again by unprotecting the Conversion sheet (right-click the tab), selecting the cells and and changing the cell style from "InterimResult" to "StandardBackground".

lortordermur avatar Aug 16 '24 12:08 lortordermur

debugging

The issue seems to be in the cell G61: =DEGREES(ATAN((COS(G60 - J54)) / (COS(H54) * TAN(H60) - SIN(H54) * SIN(G60 - J54))) + G54)

Which does not agree with formulas on inverse transform. [^1]

[^1]: Wikipedia: Conversion between equatorial and galactic coordinates

jchylik avatar Aug 16 '24 13:08 jchylik

That is the formula I obtained using an equation solver^1 from, I think, the third formula under "3.2.2 Transformation" in ^2. I solved for α.

lortordermur avatar Aug 16 '24 14:08 lortordermur

By the way, for it to solve, I had to replace the constants α0, δ0 and l0 with their numeric values.

lortordermur avatar Aug 16 '24 14:08 lortordermur

Correction: It was formula 6 on page 8 of this PDF file^1 that I fed into the solver.

Here is the direct link.

lortordermur avatar Aug 16 '24 15:08 lortordermur

That is the formula I obtained using an equation solver

I see. You do not have to combine them. Or rather the issue is that by combing the formulas in this way, you kind of remove some information. (ATAN is defined for all real numbers, but its range of values is only between -π/2 and π/2)

Just as the solver says: Warning: some solutions might be lost

jchylik avatar Aug 16 '24 15:08 jchylik

Oops, then by being "lossy" that solver was the only one able to cope with that transformation formula. The Mathway one refused for example.

But there has to be a way to resolve the left side of the formula for α.

I am clueless for the moment.

lortordermur avatar Aug 16 '24 15:08 lortordermur

But there has to be a way to resolve the left side of the formula for α.

Yes, there is, but you are losing some of the solutions.

The equation 5 is clear to invert: the values of \delta are always between -90° and 90°, same as the range of ASIN().

However when you solve the equation 6 the way described in the calculator, you are limiting results only on range between 102° and 282°.

jchylik avatar Aug 16 '24 15:08 jchylik

... And that is why we need to calculate right hand side of all three equations in 5.2.2 (and btw. in 5.2.1 as well)

  • If rhs3 is positive then the solution is ACOS( rhs2 )+ \alpha_0
  • If rhs3 is negative, then 2/π - ACOS( rhs2)+ \alpha_0

jchylik avatar Aug 16 '24 15:08 jchylik

Yes, I counter-checked using the NED coordinate calculator and I see issues with very small values of b < 0.48.

So we need an IFS branch with a separate formula for negative and positive values? Could we also limit input to 0-360/0-90 like the NED calculator?

What document/article are you referring to with the paragraphs? Can't find it in my pinned tabs.

lortordermur avatar Aug 16 '24 15:08 lortordermur

So we need an IFS branch with a separate formula for negative and positive values?

Yes. Either way you need to calculate right hand side of all three equations in 3.2.1 and 3.2.2 ^3. The linked exercise ^1 just combines them in one.

Could we also limit input to 0-360/0-90 like the NED calculator?

Could? Yes, but then the calculator would then cover only half of the sky.

jchylik avatar Aug 16 '24 16:08 jchylik

Ok, then I will play around a bit with the formula systems (either later or tomorrow) and see what I get. I still need to run them through the solver of course to resolve for the coordinate variables.

lortordermur avatar Aug 16 '24 16:08 lortordermur