[Home]UnderDark3/Utils.java

Robo Home | UnderDark3 | Changes | Preferences | AllPages

Utils.java


package matt;

import java.awt.geom.Point2D;
import java.lang.String;

public class Utils {

    //Not Mine  
    public static double normalizeBearing(double angle) {
        while (angle >  180)
            angle -= 360;
	while (angle < -180)
            angle += 360;
	return angle;
    }

    //Not Mine   
    public static double absoluteBearing(double x1, double y1, double x2, double y2) {
        double xo = x2-x1;
	double yo = y2-y1;
	double hyp = Point2D.distance(x1, y1, x2, y2);
	double arcSin = Math.toDegrees(Math.asin(xo / hyp));
	double bearing = 0;

	if (xo > 0 && yo > 0) {
            bearing = arcSin;
	} else if (xo < 0 && yo > 0) {
            bearing = 360 + arcSin;
	} else if (xo > 0 && yo < 0) {
            bearing = 180 - arcSin;
	} else if (xo < 0 && yo < 0) { 
            bearing = 180 - arcSin;
	}

	return bearing;
    }
    
    //Not Mine
    public static double rollingAvg(double value, double newEntry, double n, double weighting ) {
        return (value * n + newEntry * weighting)/(n + weighting);
    }
    
    public static boolean strContains(String base, String target){
        base = base.toUpperCase();
        target = target.toUpperCase();

        for(int l = 0; l < base.length(); l++){
            if(target.length()>(base.length()-l)){
                return false;
            }
            if(base.substring(l,l+1).equalsIgnoreCase(target.substring(0,0+1))){
                int s = 0;
                boolean ok = true;
                while(ok){
                    if(s>=target.length()){
                        return true;
                    }
                    if(!(base.substring(l+s,l+s+1).equalsIgnoreCase(target.substring(s,s+1)))){
                        ok=false;
                    }
                    s++;
                }
            }
        }
        return false;
    }
}

Questions, Comments, or anything else

Robo Home | UnderDark3 | Changes | Preferences | AllPages
Edit text of this page | View other revisions
Last edited July 11, 2005 23:38 EST by UnderDark (diff)
Search: