?? shape.java
字號:
package Painter;
import java.awt.*;
import java.lang.Math;
import java.io.Serializable;
/*
軟件作者: 熊錫君,時守剛
軟件版權(quán)歸作者所有,其他人可以對軟件進行修改,可以使用軟件代碼,(按類使用請保留作者信息)
*/
public class Shape implements Serializable{
Color m_ColorPen; //筆色
Color m_ColorBrush; //刷顏色
int m_LineWide; //線寬
public boolean IsPoint(int x,int y,float j1){return false;}
// 畫圖,每個自定義圖形都必須實現(xiàn)該接口。
public void draw(Graphics g,int m_DrawMode,Color bgColor){} //m_DrawMode = 0 默認畫圖,m_DrawMode = 1 選中畫圖
// 計算兩點距離sqrt
public float DisPoint(int x1,int y1,int x2,int y2)
{
return (float)Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
// 點到直線距離
public float PointLine(int xx,int yy,int x1,int y1,int x2,int y2)
{
float a,b,c,ang1,ang2,ang;
//計算三條邊的距離
a = DisPoint(x1,y1,xx,yy);
if(a == 0.0) return (float) 0.0;
b = DisPoint(x2,y2,xx,yy);
if(b == 0.0) return (float) 0.0;
c = DisPoint(x1,y1,x2,y2);
if(c == 0.0) return a;
if(a < b)
{
if(y1 == y2)
{
if(x1 < x2)
ang1 = 0;
else
ang1 = (float)Math.PI;
}
else
{
ang1 = (float)Math.acos((x2 - x1) / c);
if(y1 > y2)
ang1 = (float)Math.PI * 2 - ang1;
}
ang2 = (float)Math.acos((xx - x1) / a);
if(y1 > yy) ang2 = (float)Math.PI * 2 - ang2;
ang = ang2 - ang1;
if(ang < 0) ang = -ang;
if(ang > Math.PI)ang = (float)Math.PI *2 - ang;
if(ang > Math.PI/2) return a;
else
return (a * (float)Math.sin(ang));
}
else
{
if(y1 == y2)
{
if(x1 < x2)
ang1 = (float)Math.PI;
else
ang1 =0;
}
else
{
ang1 = (float)Math.acos((x1 -x2)/c);
if(y2 > y1) ang1 = (float)Math.PI * 2 - ang1;
}
ang2 = (float)Math.acos((xx - x2)/b);
if(y2 > yy) ang2= (float)Math.PI * 2 - ang2;
ang = ang2 - ang1;
if(ang < 0) ang = -ang;
if(ang > Math.PI)ang = (float)Math.PI *2 - ang;
if(ang > Math.PI/2) return b;
else
return (b * (float)Math.sin(ang));
}
}
public Shape(){
}
public Shape(Color colorPen, Color colorBrush, int lineWide) {
m_ColorPen = colorPen;
m_ColorBrush = colorBrush;
m_LineWide = lineWide;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -