22 May 2007

Java Astro Library

Astrology for Dogs Ten years ago I had a little interest in astrology. I studied some books and had the idea for an astro-chart real-time watch, some kind of watch that shows the wheel chart for the actual time just like a simple wristwatch. After releasing my Zodiac Watch applet in 2000 I got a lot of requests for its source. So I created AstroLib as branch from Zodiac Watch applet's source in 2003. I removed all painting and user interface routines to create a library.

This is AstroLib
... a free Java library for astro charting calculations. There are house system and planet position calculation methods together with date/time and location conversion routines. For a given time the positions of the planets in the zodiac are calculated. There is no code for graphical representations or drawing a chart. The library contains just methods for calculating the data needed to build a chart. Some methods were simply ported from Walter 'Cruiser1' Pullen's Astrolog 5.40 (which is written in C) and converted to Java. Part of the code is commented in German, but variables and methods are all named in English.

The library is used as shown in the Demo class' main method:
   // get a horoscop instance
TextHoroscop horoscop = new TextHoroscop();
// set your desired planet position calculation algorithm
horoscop.setPlanet(new PlanetAA0());
// set your desired house system calculation algorithm
// may be anything from the at.kugel.zodiac.house package.
horoscop.setHouse(new HousePlacidus());
// set your user data time value
horoscop.setTime(1, 12, 1953, 20);
// set your user data location value
horoscop.setLocationDegree(-16 - 17.0/60, 48 + 4.0/60);
// calculate the values
horoscop.calcValues();
// do something with the data, e.g. output raw data
System.out.println(horoscop.toString());
In case you want to add or change something, there are the following packages:
  • The main package contains the TextHoroscop class, which uses the house system and planet calculation classes to calculate the astro-chart data.
  • util contains some independent calculation utility functions and classes.
  • planet contains the different planet position calculation algorithms. This package is only dependent on the util package. All planet position algorithms are subclasses of PlanetBasic which itself implements PlanetInt. New and more accurate planet position algorithms must implement PlanetInt and may wish to extend PlanetBasic to inherit common functionality, but are not forced to do so. There is only PlanetAA0 available at the moment, which is not very accurate.
  • house contains the different house systems. All house system calculation algorithms are subclasses of HouseBasic which itself implements HouseInt.
Download and Installation
Download AstroLib 1.13 (70 KB), together with source. Extract the astrolib-*.zip and add astrolib.jar to your classpath. AstroLib is JDK 1.1 compliant and does not depend on any other libraries. AstroLib is Open Source under the GPL license.

The library is not actively developed any more, in fact it never was. The last changes I made were adding the Demo class in 2004 and fixing a bug using time zones in 2005 (thanks to Rastislav Szabo for reporting it). Today I reformatted the code and fixed some warnings. That's it folks.

FAQ
Q: Are there any chart drawing functions as in Zodiac Watch? A: Unfortunately the drawing routines are tightly coupled to the applet code and the browser user interface. I was able to extract the calculation routines and put them into a separate package, but this is not possible for the drawing code itself.

Q: The co-ordinates of the planets are within 1 minute difference from other available chart generation programs. But for the co-ordinates of the moon there is a 10 to 20 degree difference and the positions of the houses are absurd. What is wrong? A: Using a wrong time-zone results in a wrong local time. This affects the moon and the houses, but not the slower moving objects. Also make sure to enter negative longitude in the east zone and negative latitude below equator.

Q: Is there any code for computing the nodes of the moon? A: No, AstroLib can't do that.

Q: What kind of zodiac is calculated: Actual constellation divisions or the classic 30 degree each division? A: Traditional 30 degree per sign.

My First Astrology Computer

Update 24 April 2009

Jastrolog - Astrolog Port

Christian just convinced me to start a new project on SourceForge: Jastrolog, an Astrolog Port. Astrolog is a free astrology software program since 1991. Astrolog can create horoscopes, natal charts, and calculate current planetary positions in sidereal, traditional, and heliocentric formats. We believe it to be a bit of a cultural legacy. It deserves to live into the 21st century. As long as it is in C/C++ it has no chance. We might use AstroLib as a starting in porting the whole Astrolog and/or Astrolog32 to Java.

45 comments:

astro said...

have you developed this thing more and it gives western birth charts i believe any code to generate vedic astrology charts

Peter Kofler said...

Dear astro, I am sorry, but the code has not been developed any further. And AFAIK the Jastrolog project has not made any progress either. So you are on your own.

I'm not sure what you mean with western birth charts, the code calculates birth/natal charts and all common house systems.

Peter Kofler said...

I'm posting an answer to an email here, as it might be of interest to everybody:

Just found your "Zodiac Watch". The Manual of Computer Programming for Astrologers by Michael Erlewine is out of print since long, but I'm looking for it desperately. Regards, ...

I bought the book in 2000 directly from Matrix Software. Well, calling it a book is exaggerated, it's a bunch of (badly) copied pages. Even worse, the programs given inside are Commodore 64 BASIC, which is not even procedural. Due to optimisations that Michael Erlewine had to perform back then, the code is very difficult to understand. The formulas are not explained, just given as code. Due to my experience with Commodore 64 BASIC back in the 80ties I was able to figure out some parts of it.

I am offering to make a physical copy for you, but I'm not sure it's worth the effort. I would not have bought the book if I had known that before.

Anonymous said...

Nice blog. I am very interested by your topic. astrology etc.
Si it's a pleasure for me to read your post.
I love your picture, very beautiful.
Sincerely

http://www.antiqueclockrepair.co.uk/

Peter Kofler said...

It's funny that just this single page of my blog attracts spam and all other do not. Are spam comments better than no comments at all? I don't know...

Munish Chandel said...

Hi, is there any update in this library, I am really looking for a java library to generate Vedic Horoscope chart.

Peter Kofler said...

Munish,
I am sorry I do not work on the library any more. It is provided as is.

I am not sure what you would need for a full Vedic Horoscope chart, but all the basics like signs, planets and the moon are here.

Zigomar said...

I too have bought Michael Earlewine's book (still owns the heavily annotated slab) and used the routines myself back in the days !! Sold a small number of copies of a true graphic "Astrograph" in 1982, now defunct...

I'm new to Java now, and i don't know the first thing in dispatching the Astro Library into some project - I stopped programming not long after the Object Oriented Paradigm came in, I didn't have enough time then to keep up.
So now, I have Java 7.4.5 + the fresh installed latest JDK, and, as freshly installed to choose from, the Java NetBeans and Eclipse.
Is there a way i can easily 'check-in' your code in either of these two environments ?
Thanks

Peter Kofler said...

Zigomar,
in Eclipse - if you have SVN tools installed - you go to File - New - SVN - Checkout Projects from SVN and follow the wizard. For repository URL use http://svn.code.sf.net/p/jastrolog/code/jastrolog/trunk and the project gets right into your workspace.

Have fun!

Unknown said...

http://www.th-mack.de/international/download/

Peter Kofler said...

John,
thank you for the link. It seems the text describing the link was lost, so I will repost it here (yes I really click every link on the internet ;-)

Thomas Mack's port of the Swiss Ephemeris library of AstroDienst Zürich to Java, 7th of February 2014.

Thomas' work looks good, I did not use it but it has Javadoc and all necessary downloads ready to use.

Unknown said...

Hello! I am trying to play around with your astro library, but I am not sure how I should set the minutes for the time in TextHoroscop.setTime(). I tried as follows: (hours + minutes / 60 - timezone) where minutes are given as a floating-point number: 50.0 for example. I noticed that in this situation I have a slight difference from the calculations made with Astrolog 5.40 - the value for the Moon is two angular minutes less with astro library than with Astrolog 5.40, and the Ascendant value is one angular minute less. Please note, that to my opinion I am using the time-zone correction, and coordinates the right way, and the difference is so small, it couldn't be caused by any of those. So, am I setting the minutes the right way, and is this slight difference expected then, or could it be caused by the fact I don't set the minutes the right way?

Peter Kofler said...

Rumen,
when using /60 the result gets truncated by Java. Try minutes/60.0 instead (with extra decimal point). The slight difference could result from truncating the decimal minutes.

You can also use the second setTime(int day, int month, int year, int h, int m, int s, double timeZone).

Unknown said...

Hello Peter,

Thank you for your quick reply! Unfortunately I get absolutely the same result when using minutes/60.0, or the extended setTime() method - still the same misalignment to the results from Astrolog 5.40.

Peter Kofler said...

Rumen,
sorry I did not read proper, you already wrote that the types of your variable minutes is float, so it is not truncated and my answer is wrong.

I checked my source now, I only use "AA0" algorithm, which is from the original Erlewine book which also Astrolog depends on.

Afaik Astrolog 5.4 has another, newer and more accurate algorithm inside. The AA0 (no idea what the name means) should have 1 degree of accuracy. This might cause the difference. As you describe a "angular minutes" difference, I would say the results are pretty similar (1/30 - 3% off). While the moon calculation method is different from the other planets, the idea stays the same.

Also note that planet position algorithms are always approximations using some fixed formulas and never be exact - neither do they need to be for astrological interpretation.

The house boundaries calculations should really be the same, except maybe machine precision. I can not remember the data type Astrolog 5 used internally, but Java has the double type and calculations might differ after a certain number of digits. Also house is affected by long/lat - did you double check these?

Unknown said...

Hello Peter,

Yes, you are right that the offset actually is quite low, so it really is not a big deal at least with my test data. I hope also it stays withing the same amount with any data! I think longitude/latitude are set correctly in my case - I just followed closely the example. Anyway this type of precision should be enough for me as long as it stays consistent with any type of input data.

Kamal said...

like your library a lot. would give it a shot at enhancing it .. wish me luck :)

zolive said...

Hi Kamal, do you have something new to give to us ?
You were speaking about enhancing it...

I'll start using that package right now, for my musical astral clock...
:)

Peter Kofler said...

Olivier,
I am not aware of any extensions or further development of this package. Musical astral clock sounds great. Please share how it went afterwards.

zolive said...

Yes, for sure.
I have done it and all the ideas attached to it some... 30 years back, on my own made computer and own made basic language...

The app is ok, but now I use a web service for calculation witch give problem. So I'll do it with your library.
It will be done in one week I guess :)

dvd said...

I have a question concerning your astro library. The zodiac girdle needs to be rotated a bit, but where can I get the amount of degrees it needs to be rotated in the printout of your library?, is it the degree is in the sideral time ? mine prints out "SZ: 15°44'45";" so this means that the signs have to rotate 15 degrees counter-clockwise?

Peter Kofler said...

dvd,
afaik the zodiac is presented in a way that the Ascendant (AC) is left and the MC is on top. While the MC depends on your house system I believe the AC is always the same because it is the start of all house systems. By looking at the code of HouseEqual you can see that it takes the ascendant and the siderealOffset. Unfortunately I can not remember exactly what the siderealOffset was. Hope this helps.

dvd said...

Thank you for the fast response!!, I have another question; how can I find out how much degrees the zodiac needs to be rotated? (to the left or right), Is it enough to convert world time into degrees? degrees = worldtime*15. Or do I need another approach?

dvd said...

My guess its 'rightascension' in TextHoroscop, is this right?

Peter Kofler said...

dvd,
hm, I am sorry I do not know. I displayed the zodiac in another way and did not care about that.

I recommend you create a reference zodiac with some online program and tweak the code until it looks the same. It is probably one of the given values. I did that when I fine-tuned the library.

Good luck!

dvd said...

Okay, I will just do that ;)

Chandan said...

Thanks Kofler for sharing the library. I will go through it. For long days I am searching the method to calculate the planetary positions. Can you kindly share which book to refer for calculating planetary positions?

email: chandankumohanty@gmail.com
chandankumohanty@yahoo.co.in

Peter Kofler said...

Chandan,
I took the formulas from The Manual of Computer Programming for Astrologers by Michael Erlewine. It is a very old book and the code was given in Commodore 64 BASIC.

dvd said...

I have a question concerning the coordinate system;

how must I interpret the numbers....

You used
latitude(?) -16 - 17.0/60
longitude(?) 48 + 4.0/60

Are these degrees & seconds, or minutes & seconds ?

Furthermore, The latitude is under the equator (-),
and the longitude is in the west (+) in this example?

Peter Kofler said...

These values are degrees and minutes. Seconds would be 1/60/60.
The values are from Vienna, Austria, north and east.

dvd said...

Thank you!, now I know how to interpret the data properly!
The astrological charts now look exactly like the ones I compare them with, and I have none of those weird Errors anymore ;)

Unknown said...

hey everybody,

first of all i have to say great work on the library, im having a lot of fun with it.

but i have a question or concern:

can i add planets/bodies to the calculation?

for example i want to add chiron, lilith and the nodes..

how would i be able to do that?

kindly

fx

Peter Kofler said...

Unknown,
thank you. I like to hear that the code is still useful to someone.

I believe it is possible to add planets/bodies that go around the sun. In the class PlanetAA0 you would need to add their Anomaly (3 values), Eccentricity (3 values), SemiMajor Axis (1 value), Periphelion (3 values) Ascending Node (3 values) and Inclination (3 values). Unfortunately I have no idea where you would get these values from. In theory if you find some rule for calculations, and it contains the values the code uses for the planets, and more values you could add them. Maybe the values can be found in the source code of the Astrolog (http://www.astrolog.org/astrolog.htm) which was plain C, but you would only need the values, no code. Maybe, maybe, this is just a wild idea. Sorry I do not have more details here.

Further I found some comments in the calculateMoon method, which indicates it could calculate North Lunar Node. I am not sure if you are referring to this.

Hope this helps,
Peter

Unknown said...

hey,

i solved the problem using the swissephemeris by thomas mack

ive tried it before but couldnt calculate julian days, which i am now able to ^^

another question though :

how can i display astrological symbols like planets and aspects ??

this would really help me out

cheers :)

zolive said...

Hey Unknow :)
Thanks for the info about swissephemeris that will help me too.

I'm to publish soon an app (based on that Java Astro library) witch gives you the astral music on live or on a specific birth. It is also a clock to play every 10 minutes a fragment of the full music. Will tell here when it get ready.

For the symbols and aspects, I use Symbola font. All aspects are not there, but signs and planets are ok as unicode standard.

Hope it will help...

Olivier

zolive said...

You can also get icons here https://icons8.com/web-app/category/all/Astrology


If you know any fonts to display aspects, please give it to us !

Unknown said...

Hello,
I have a Vedic Astrology practice and website and I would like to include a: "Calculate your Vedic chart" feature on it. I don't need the picture of a chart, just the degree of the Ascendant and the planets in the various signs and nakshatras. I have been looking unsuccessfully for someone to write the code for it and embed it into my website. Would you be able and interested to help with this type of project? Thank you!

zolive said...

Hi Oana,
I'm very interested in... vedic astrology too. So we can keep in touch about that project you have ?

I take this occasion to give that announcement : astroMuse, my astral music player and astral clock is available on the Play store !
All feedback eagerly waiting !

https://play.google.com/store/apps/details?id=org.protee.iastromuse&hl=fr

My email is on the bottom :)

zolive said...

You will see that there is a very "beginning" for vedic display. This is my next challenge.

dvd said...

Hiii CodeCop!

I used your library for my art project, I got some (last?) bugs ironed out and now its finished! You can give me your info and send you an unique artpiece ;)
Together with an archetypal based analysis. The first thing you will see on the site is a small side-project. So scroll a lil down.

http://www.astrothesia.com/

Peter Kofler said...

Hi dvd, that images/prints look great. Well done. Thank you for offering

Juergen said...

Hello Peter,
I've downloaded AstroLib and try to use it in "Android Studio" for testing. Is it possible to get a list of the planets and houses positions or only using .ToString()?
Is it possible to get Chiron to?
Thanks for your answers.
Regards
Juergen

Peter Kofler said...

Juergen,
use the methods String[] getPlanetsText() and double[] getPlanetsR() from PlanetAA0 to get two arrays of planet names and their positions in radiant (suffix R) on the wheel.

Similar methods are available in houses, use String[] getHousesText() and double[] getHousesR().

zolive said...

Yes, and what about Chiron ?
I use this library from 6 years know, and it is good !
In a mobile app on android, an astral clock playing music based on planets...

Peter Kofler said...

Chiron is not calculated. It is an asteroid and that was not included in the material I used to write the calculations. (Or I did not know and did not copy the specific material.) The current code only calculates planet and house positions. As Chiron is moving slowly, you could use tables like that to get an idea where Chiron is right now.