com.gwac.util.SearchBoxSphere.java Source code

Java tutorial

Introduction

Here is the source code for com.gwac.util.SearchBoxSphere.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.gwac.util;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 *
 * @author xy
 */
public class SearchBoxSphere {

    private static final Log log = LogFactory.getLog(SearchBoxSphere.class);

    private double ra;
    private double dec;
    private double minRa;
    private double maxRa;
    private double minDec;
    private double maxDec;
    private double searchRadius;

    public SearchBoxSphere() {
        ra = 0;
        dec = 0;
        minRa = 0;
        maxRa = 360;
        minDec = -90;
        maxDec = 90;
        searchRadius = 0;
    }

    @Override
    public String toString() {
        return "ra=" + ra + ",dec=" + dec + ",minRa=" + minRa + ",maxRa=" + maxRa + ",minDec=" + minDec + ",maxDec="
                + maxDec + ",searchRadius=" + searchRadius + "\n";
    }

    public SearchBoxSphere(double ra, double dec, double searchRadius) {
        this.ra = ra;
        this.dec = dec;
        this.searchRadius = searchRadius;
    }

    public int calSearchBox() {
        return calSearchBox(ra, dec, searchRadius);
    }

    /**
     * ???searchRadius(ra,dec)??
     *
     * @param ra ???
     * @param dec ??
     * @param searchRadius ?? ??
     * @return 0,1,2. 0?????radec?searchRadius?
     * 1?0360??[minRa, maxRa]
     * 2?0360??[minRa,360][0, maxRa]
     */
    public int calSearchBox(double ra, double dec, double searchRadius) {

        int flag = 0;
        if (!(ra > 360.0 || ra < 0.0 || dec > 90.0 || dec < -90.0 || searchRadius > 20.0)) {
            minDec = dec - searchRadius;
            maxDec = dec + searchRadius;
            if (getMaxDec() > 90.0) {
                maxDec = 90;
            }
            if (getMinDec() < -90.0) {
                minDec = -90;
            }

            double tDec = Math.abs(maxDec) > Math.abs(minDec) ? Math.abs(maxDec) : Math.abs(minDec);
            ///180
            double cosd = Math.cos(tDec * 0.0174532925);
            if (cosd > searchRadius / 180.0) {
                maxRa = (ra + searchRadius / cosd + 360.0) % 360.0;
                minRa = (ra - searchRadius / cosd + 360.0) % 360.0;
            } else {
                maxRa = 360;
                minRa = 0;
            }
            if (getMinRa() > getMaxRa()) {
                /**
                 * ?0360
                 */
                flag = 2;
            } else {
                flag = 1;
            }
        } else {
            log.error("search box exceed max value");
        }
        return flag;
    }

    /**
     * @return the minRa
     */
    public double getMinRa() {
        return minRa;
    }

    /**
     * @return the maxRa
     */
    public double getMaxRa() {
        return maxRa;
    }

    /**
     * @return the minDec
     */
    public double getMinDec() {
        return minDec;
    }

    /**
     * @return the maxDec
     */
    public double getMaxDec() {
        return maxDec;
    }

}