資源簡介
檢查線段是否位于第一象限check…
? 求線段的長度 length() …
? 判斷兩條線段(非延長線)是否相交(另一線段作為參數)。
? 求一點到該線段(或延長線)的距離
代碼片段和文件信息
import?java.awt.Point;
import?java.lang.Math;
import?java.io.*;
public?class?MyLine?{
private?Point?e1;
private?Point?e2;
MyLine(Point?p1Point?p2)
{
e1=p1;
e2=p2;
}
void?check1()
{
????if(e1.x>0&&e1.y>0&&e2.x>0&&e2.y>0)
????System.out.println(“線段位于第一象限“);
????else
????System.out.println(“線段不在第一象限“);
}
public?float?length()
{
????return?(float)java.lang.Math.sqrt((e1.x-e2.x)*(e1.x-e2.x)+(e1.y-e2.y)*(e1.y-e2.y));
}
void?check2(Point?p1Point?p2)
{
double?mn;
m=(p1.y-p2.y)/(p1.x-p2.x);
????????n=(e1.y-e2.y)/(e1.x-e2.x);
if(m==n)
???????????System.out.println(“兩線段不相交“);
else
???System.out.println(“兩線段相交“);
}
void?distance(Point?p)
{
double?ijksumareadis;
k=Math.sqrt((p.x-e1.x)*(p.x-e1.x)+(p.y-e1.y)*(p.y-e1.y));
j=Math.sqrt((e2.x-p.x)*(e2.x-p.x)+(e2.y-p.y)*(e2.y-p.y));
i=Math.sqrt((e1.x-e2.x)*(e1.x-e2.x)+(e1.y-e2.y)*(e1.y-e2.y));
sum=i+j+k;
area=Math.sqrt((sum/2-k)*(sum/2-j)*(sum/2-i)*sum/2);
dis=2*area/i;
System.out.println(“點到線段的距離為“+(float)dis);
}
?public?static?void?main(String?args[])?throws?IOException
?{
??String?s1s2s3s4s5s6s7s8s9s10s11;
??BufferedReader?buf=new?BufferedReader(new?InputStreamReader(System.in));
??System.out.println(“線段端點x1:“);
??s1=buf.readLine();
??int?x1=Integer.parseInt(s1);
??System.out.println(“線段端點y1:“);
??s2=buf.readLine();
??int?y1=Integer.parseInt(s2);
??System.out.println(“線段端點x2:“);
??s3=buf.readLi
- 上一篇:android rss閱讀器源碼
- 下一篇:Volley的Jar包
評論
共有 條評論