📄 myline.java
字号:
import java.awt.geom.*;
public class MyLine {
public Point end1;
public Point end2;
public MyLine() {
//System.out.println("MyLine(){} Constructor!");
end1 = new Point();
end2 = new Point();
}
public MyLine(Point p1 , Point p2) {
end1 = new Point(p1);
end2 = new Point(p2);
}
public boolean Check(){
if (end1.Check())
{
if (end2.Check()) return true;
else return false;
}
else return false;
}
public double Length () {
double xLength;double yLength;
xLength = end2.GetX()-end1.GetX();
yLength = end2.GetY()-end1.GetY();
double value = Math.sqrt(xLength * xLength + yLength * yLength);
return value;
}
public double Distance(Point p) {
double x;double y;
x = p.GetX();y = p.GetY();
return Distance(x,y);
}
public double Distance(double x,double y){
Point C;
C = new Point(x,y);
MyLine AC;MyLine BC;
AC = new MyLine(end1,C);BC = new MyLine(end2,C);
double a;double b;double c;
a = BC.Length();b = AC.Length();c = Length();
double s;
s = (a + b + c)/2;
double area;
area = Math.sqrt(s*(s-a)*(s-b)*(s-c));
double distance;
distance = area*2/Length();
return distance;
}
public boolean IsIntersectant (MyLine line2) {
if (Line2D.linesIntersect(end1.GetX(), end1.GetY(), end2.GetX(), end2.GetY(), line2.end1.GetX(), line2.end1.GetY(), line2.end2.GetX(), line2.end2.GetY())) return true;
else return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -