1.public List<point> Getpoints(Point start,Point end,bool extension)
start:起始坐標
end:結束坐標
extension:是否將像素線由起點經過終點延長到螢屏邊緣,如果為true則回傳這條坐標線的所有坐標
回傳值:回傳一個包含所有像素坐標的List集合
要求:所有坐標點繪制出來的1*1的圓效果在螢屏上顯示出來是一條實心線
2.public int Getangle(Point start,Point end)
回傳這兩個點連成線之后以起始點為底邊的夾腳度數
uj5u.com熱心網友回復:
public List<Point> GetPoints(Point start, Point end, bool extension)
{
bool isZhengX = end.X > start.X; //X是否遞增
bool isZhengY = end.Y > start.Y; //Y是否遞增
Point pScreen = new Point(SystemInformation.PrimaryMonitorSize.Width, SystemInformation.PrimaryMonitorSize.Height); //螢屏最大坐標
int xRange = end.X - start.X;
int yRange = end.Y - start.Y;
List<Point> listPoint = new List<Point>();
int currX = start.X;
int currY = start.Y;
if (xRange != 0)
{
int destX = extension ? (isZhengX ? pScreen.X : 0) : end.X;
while (isZhengX ? currX < destX : currX > destX)
{
listPoint.Add(new Point(currX, yRange == 0 ? currY : ((int)(currX * (yRange / (float)xRange)))));
currX = isZhengX ? (currX + 1) : (currX - 1);
}
}
else if (yRange != 0)
{
int destY = extension ? (isZhengY ? pScreen.Y : 0) : end.Y;
while (isZhengY ? currY < destY : currY > destY)
{
listPoint.Add(new Point(currX, currY++));
}
}
return listPoint;
}
public double Getangle(Point start, Point end)
{
double hudu = Math.Atan2(end.Y - start.Y, end.X - start.X); //180°為π
double du = hudu * 180 / Math.PI;
return du;
}
uj5u.com熱心網友回復:
謝謝大佬,回去我就試試
uj5u.com熱心網友回復:
沒看懂第一個方法的要求uj5u.com熱心網友回復:
public List<Point> GetPoints(Point start, Point end, bool extension)
{
bool isZhengX = end.X > start.X; //X是否遞增
bool isZhengY = end.Y > start.Y; //Y是否遞增
Point pScreen = new Point(SystemInformation.PrimaryMonitorSize.Width, SystemInformation.PrimaryMonitorSize.Height); //螢屏最大坐標
int xRange = end.X - start.X;
int yRange = end.Y - start.Y;
List<Point> listPoint = new List<Point>();
int currX = start.X;
int currY = start.Y;
int destX = extension ? (isZhengX ? pScreen.X : 0) : end.X;
int destY = extension ? (isZhengY ? pScreen.Y : 0) : end.Y;
if (xRange != 0)
{
while (isZhengX ? currX <= destX : currX >= destX)
{
int addy = (int)((currX - start.X) * yRange / (float)xRange);
int y = currY + addy;
if (isZhengY ? y > destY : y < destY)
{
break;
}
listPoint.Add(new Point(currX, y));
currX = isZhengX ? (currX + 1) : (currX - 1);
}
}
else if (yRange != 0)
{
while (isZhengY ? currY <= destY : currY >= destY)
{
listPoint.Add(new Point(currX, isZhengY ? currY++ : currY--));
}
}
return listPoint;
}
uj5u.com熱心網友回復:
計算機圖形學基礎,請百度uj5u.com熱心網友回復:
第一題什么意思?繪制出邊框?轉載請註明出處,本文鏈接:https://www.uj5u.com/net/86349.html
標籤:C#
