[Home]UnderDark3/Utils.java

Robo Home | UnderDark3 | Changes | Preferences | AllPages

Difference (from prior major revision) (minor diff)

Changed: 2,3c2


<font face="courier" size=3>

<pre>

Changed: 10c9,10


//Not? Mine

Changed: 18c18,19


//Not? Mine

Added: 38a40
//Not? Mine

Added: 45a48


Changed: 67,68c70
</font>


</pre>


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 12, 2005 1:38 EST by UnderDark (diff)
Search: