util.java

来自「卡耐基.梅隆大学的机器人仿真软件(Redhat linux 9下安装)」· Java 代码 · 共 52 行

JAVA
52
字号
package Carmen;/** Carmen class with utilities that provide unit conversion, basic trig, and host information retrieval */public class Util {  public static double getTime() {    return (double)(System.currentTimeMillis() / 1000.0);  }  /** returns the length of hypotenuse of right angled triangle */  public static double hypot(double x, double y) {    return Math.sqrt(x*x+y*y);  }  /** ensures that theta is in the range -PI to PI */  public static double normalizeTheta(double theta) {    int multiplier;        if (theta >= -Math.PI && theta < Math.PI)      return theta;        multiplier = (int)(theta / (2*Math.PI));    theta = theta - multiplier*2*Math.PI;    if (theta >= Math.PI)      theta -= 2*Math.PI;    if (theta < -Math.PI)      theta += 2*Math.PI;        return theta;  }  /** returns host name */  public static String getHostName() {    String hostname = null;    try {      java.net.InetAddress localMachine =	java.net.InetAddress.getLocalHost();	      hostname = java.net.InetAddress.getLocalHost().toString();    }    catch(java.net.UnknownHostException uhe) {      System.err.println("Could not recover hostname.\n"+			 "Is the network functioning properly? Is the"+			 "nameserver working?");      System.exit(-1);    }    return hostname;      }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?