public class Trigon {
public static void main(String[] args) {
double x1 = 9;
double y1 = 9;
double x2 = 4;
double y2 = 4;
Point sp = new Point(x1,y1);//sp是直线上的一点
Point tp = new Point(x2,y2);//tp是直线上的另一点,也是三角形的顶点
double arrowWidth = 3; //设置三角形的半边底长
double arrowHeight = 6; //设置三角形的高
double angle = Math.atan2(tp.y-sp.y, tp.x-sp.x); //求已知直线的倾斜角
System.out.println("该直线的倾斜角度是:" + angle);
double point_x1 = tp.x-arrowHeight*Math.cos(angle)-arrowWidth*Math.sin(angle);
double point_y1 = tp.y-arrowHeight*Math.sin(angle)+arrowWidth*Math.cos(angle);
double point_x2 =tp.x-arrowHeight*Math.cos(angle)+arrowWidth*Math.sin(angle);
double point_y2 = tp.y-arrowHeight*Math.sin(angle)-arrowWidth*Math.cos(angle);
Point p1 = new Point(point_x1,point_y1);
Point p2 = new Point(point_x2,point_y2);
p1.out();
p2.out();
}
}
//定义定点类
class Point{
double x;
double y;
public Point(){}
public Point(double x, double y){
this.x = x;
this.y = y;
}
public void out(){
System.out.println("该顶点的X坐标:" + x);
System.out.println("该顶点的Y坐标:" + y);
}
}
参考:http://blog.csdn.net/james999/archive/2008/09/05/2885380.aspx
posted on 2008-11-12 10:09
jiafang83 阅读(678)
评论(0) 编辑 收藏