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
// do something with the data, e.g. output raw data
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.

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.


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.

brian 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.


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...

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 ?

Peter Kofler said...

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!

John Smith said...


Peter Kofler said...

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.

Rumen Botev 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...

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).

Rumen Botev 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...

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?

Rumen Botev 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 :)

Grimbert Olivier 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...

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

Grimbert Olivier 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 :)