directjudge.java

来自「地理信息系统中」· Java 代码 · 共 68 行

JAVA
68
字号
package com.mapabc.lse.spatial;

import com.mapabc.geom.DoublePoint;

/**
 * used to judge the direction of two geometry
 * @author user
 *
 */
public class DirectJudge {

    public static String  North = "北";
    public static String  South = "南";
    public static String  West = "西";
    public static String  East = "东";
    public static String  EastNorth = "东北";
    public static String  WestNorth = "西北";
    public static String  EastSouth = "东南";
    public static String  WestSouth = "西南";

    /**
     * Return the derection information of two point
     * @param point1
     * @param point2
     * @return
     */
    public static String getDirect(DoublePoint point1,DoublePoint point2)
    {
    	double Dx = point2.x - point1.x;
    	double Dy = point2.x - point1.y;
    	
  
    	if(Dx == 0 && Dy > 0) return North;
    	if(Dx == 0 && Dy < 0) return South;
    	if(Dx > 0 && Dy == 0) return East;
    	if(Dx < 0 && Dy == 0) return West;
    	
    	if(Dx > 0 && Dy > 0) return EastNorth;
    	if(Dx > 0 && Dy < 0) return EastSouth;
    	if(Dx < 0 && Dy < 0) return WestNorth;
    	if(Dx < 0 && Dy > 0) return WestSouth;
    	else  return("同一个点");
    }
    
    /**
     * Return the direction of a point relative a line
     * @param line
     * @param point2
     * @return
     */
    public String getDirect(DoublePoint[] line,DoublePoint point2)
    {
    	return "";
    }
    
    /**
     * 角度运算
     *    function calAngle():Number {
              var k1:Number = (line1.y1-line1.y2)/(line1.x1-line1.x2);
              var k2:Number = (line2.y1-line2.y2)/(line2.x1-line2.x2);
              var angle1:Number = Math.abs(Math.atan(k1)/(Math.PI/180));
              var angle2:Number = Math.abs(Math.atan(k2)/(Math.PI/180));
              return Math.abs(angle1-angle2);
       }

     */
}

⌨️ 快捷键说明

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