edu.jhu.htm.core
Class HTMfunc

java.lang.Object
  |
  +--edu.jhu.htm.core.HTMfunc

public class HTMfunc
extends java.lang.Object

These are the core routines for the HTM. They are a direct lift from cc_aux but modifed along the lined of the new design In pratically all cases below a double[] is a vector of 3 numbers representing x,y,z in the unit sphere.

  Current Version
  ===============
  ID:	$Id: HTMfunc.java,v 1.5 2003/02/19 15:46:11 womullan Exp $
  Revision: 	$Revision: 1.5 $
  Date/time:	$Date: 2003/02/19 15:46:11 $
 


Field Summary
static double Epsilon
           
static double HTM_INVALID_ID
           
static int HTMNAMEMAX
           
static long IDHIGHBIT
           
static long IDHIGHBIT2
           
static int IDSIZE
           
static int iN0
           
static int iN1
           
static int iN2
           
static int iN3
           
static int iS0
           
static int iS1
           
static int iS2
           
static int iS3
           
static double Pi
           
static double Pr
           
static double sqrt3
           
static boolean verbose
           
 
Constructor Summary
HTMfunc()
           
 
Method Summary
protected static void copy_vec(double[] d, double[] s)
          simple utility funtion which copies one vector over another.
static double distance(double[] v1, double[] v2)
          return the angular distance between two vectors ACOS (V1 .
static double distance(long htmId1, long htmId2)
          return the angular distance between two htmids gets the vectors of the mid points and uses thoose to compute distance
static double distance(java.lang.String htm1, java.lang.String htm2)
          return the angular distance between two htm names gets the viectors of the mid points and uses thoose to compute distance
static int idLevel(long htmid)
          idLevel is a trusting method (assumes that the id is well formed and valid) that returns the level of the trixel represented by the given 64 bit htmId.
static java.lang.String idToName(long id)
          Walk the bits of the id and convert it to a string like N012.
static double[] idToPoint(long htmId)
          gets the name from the id and calls idToPoint with it.
static double[] idToPoint(java.lang.String name)
          for a given ID get back the approximate center of the triangle.
static boolean isinside(double[] p, double[] v1, double[] v2, double[] v3)
          for a given vector p is it contained in the triangle whose corners are given by the vectors v1, v2,v3.
static java.lang.String lookup(double x, double y, double z, int depth)
           
static java.lang.String lookup(double ra, double dec, int depth)
          For given ra and dec lookup the HTMID to given depth HTM works in vectors so this basically converts ra dec to a vector and calls lookup for the vector.
static long lookupId(double x, double y, double z, int depth)
          looks up the name of a vector x,y,z and converts the name to an id
static long lookupId(double ra, double dec, int depth)
           
protected static void m4_midpoint(double[] v1, double[] v2, double[] w)
           
static long nameToId(java.lang.String name)
          for a given name i.e.
static java.lang.Object[] nameToTriangle(java.lang.String name)
          Like name2Id but instaed of returning the htmId return v0,v1,v2 vetors representin the corners of the trinagle
static double[] radecToVector(double ra, double dec)
          convert ra dec to a vector
protected static int startpane(double[] v1, double[] v2, double[] v3, double xin, double yin, double zin, java.lang.StringBuffer name)
          where to start in the HTM quadtree when looking for a vectors home xin yin zin are thin input vector v1 v2 v3 and name are loaded with the initial tringle points and the name of the triangle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

verbose

public static boolean verbose

Pi

public static double Pi

Pr

public static double Pr

Epsilon

public static double Epsilon

sqrt3

public static double sqrt3

IDSIZE

public static final int IDSIZE
See Also:
Constant Field Values

IDHIGHBIT

public static final long IDHIGHBIT
See Also:
Constant Field Values

IDHIGHBIT2

public static final long IDHIGHBIT2
See Also:
Constant Field Values

HTMNAMEMAX

public static final int HTMNAMEMAX
See Also:
Constant Field Values

HTM_INVALID_ID

public static final double HTM_INVALID_ID
See Also:
Constant Field Values

iS2

public static final int iS2
See Also:
Constant Field Values

iN1

public static final int iN1
See Also:
Constant Field Values

iS1

public static final int iS1
See Also:
Constant Field Values

iN2

public static final int iN2
See Also:
Constant Field Values

iS3

public static final int iS3
See Also:
Constant Field Values

iN0

public static final int iN0
See Also:
Constant Field Values

iS0

public static final int iS0
See Also:
Constant Field Values

iN3

public static final int iN3
See Also:
Constant Field Values
Constructor Detail

HTMfunc

public HTMfunc()
Method Detail

startpane

protected static int startpane(double[] v1,
                               double[] v2,
                               double[] v3,
                               double xin,
                               double yin,
                               double zin,
                               java.lang.StringBuffer name)
                        throws HTMException
where to start in the HTM quadtree when looking for a vectors home xin yin zin are thin input vector v1 v2 v3 and name are loaded with the initial tringle points and the name of the triangle

HTMException

m4_midpoint

protected static final void m4_midpoint(double[] v1,
                                        double[] v2,
                                        double[] w)

lookup

public static java.lang.String lookup(double x,
                                      double y,
                                      double z,
                                      int depth)
                               throws HTMException
HTMException

lookupId

public static long lookupId(double x,
                            double y,
                            double z,
                            int depth)
                     throws HTMException
looks up the name of a vector x,y,z and converts the name to an id

HTMException

lookup

public static java.lang.String lookup(double ra,
                                      double dec,
                                      int depth)
                               throws HTMException
For given ra and dec lookup the HTMID to given depth HTM works in vectors so this basically converts ra dec to a vector and calls lookup for the vector.

HTMException

radecToVector

public static double[] radecToVector(double ra,
                                     double dec)
convert ra dec to a vector


lookupId

public static long lookupId(double ra,
                            double dec,
                            int depth)
                     throws HTMException
HTMException

isinside

public static boolean isinside(double[] p,
                               double[] v1,
                               double[] v2,
                               double[] v3)
for a given vector p is it contained in the triangle whose corners are given by the vectors v1, v2,v3.


nameToId

public static long nameToId(java.lang.String name)
                     throws HTMException
for a given name i.e. N301022 convert it to its 64bit htmId effectively this walks trough the string in reverse order and sets the bits of a long number according to the charector in the String. The name has always the same structure, it begins with an N or S, indicating north or south cap and then numbers 0-3 follow indicating which child to descend into. So for a depth-5-index we have strings like N012023 S000222 N102302 etc Each of the numbers correspond to 2 bits of code (00 01 10 11) in the uint64. The first two bits are 10 for S and 11 for N. For example N 0 1 2 0 2 3 11000110001011 = 12683 (dec) The leading bits are always 0

HTMException

idLevel

public static int idLevel(long htmid)
idLevel is a trusting method (assumes that the id is well formed and valid) that returns the level of the trixel represented by the given 64 bit htmId. This determines the index of the first bit set by continually left shifting the htmid 2 bits at a time until a set bit is found in the highest position. 2 bits are used as each number in an HTM Name like N012 is represented by two bits. Also the number of bits used dived by two is the level of the htmId +2 we have +2 because of the N0,S1 etc prefixes. So an id with bit 64 set is level 30 (64/2 -2)


idToName

public static java.lang.String idToName(long id)
                                 throws HTMException
Walk the bits of the id and convert it to a string like N012. sucessivley look at each pair of bits and convert it to 0,1,2 or 3. Finally use the highest bit to set N or S in the string. The first bit pair gives N (11) or S (10). The subsequent bit-pairs give the numbers 0-3: (00, 01, 10, 11). Example: In the first level there are 8 nodes, and we get the names from numbers 8 through 15 giving S0,S1,S2,S3,N0,N1,N2,N3. The order is always ascending starting from S0000.. to N3333...

HTMException

nameToTriangle

public static java.lang.Object[] nameToTriangle(java.lang.String name)
Like name2Id but instaed of returning the htmId return v0,v1,v2 vetors representin the corners of the trinagle

Returns:
Object[] which is holding 3 double[] for v0 v1 v2

copy_vec

protected static void copy_vec(double[] d,
                               double[] s)
simple utility funtion which copies one vector over another. this uses System.arraycopy which should be efficient. It assumes both arrays are the same lenght however it will copy all odf s to d so theoretically d could be longer than s.

Parameters:
d - destination of copy
s - source of copy

idToPoint

public static double[] idToPoint(java.lang.String name)
                          throws HTMException
for a given ID get back the approximate center of the triangle. This may be used as an inverse of lookup however bear in mind many points may fall in a triangle while only the center point will be returned from this function. The name is used to get the triange corners and these are then averaged to get a center point. The resultant vector is not normalized.

HTMException

idToPoint

public static double[] idToPoint(long htmId)
                          throws HTMException
gets the name from the id and calls idToPoint with it.

HTMException

distance

public static double distance(double[] v1,
                              double[] v2)
return the angular distance between two vectors ACOS (V1 . V2)


distance

public static double distance(long htmId1,
                              long htmId2)
                       throws HTMException
return the angular distance between two htmids gets the vectors of the mid points and uses thoose to compute distance

HTMException

distance

public static double distance(java.lang.String htm1,
                              java.lang.String htm2)
                       throws HTMException
return the angular distance between two htm names gets the viectors of the mid points and uses thoose to compute distance

HTMException