Itay의 솔루션은 우아하고 많은 매트가 필요하지 않습니다.
당신은 그러나 더 순진 (CPU 무거운) 구현을 위해 갈 수 :
포인트의 배열로 라인을 다음 원의 중심에 각 점에서의 거리를 측정 :
방법 (I는이 메소드 간단히 테스트 한) 좌표의 배열로 광고의 모든 포인트에 원형의 중심으로부터의 거리를 계산하기
public static Point[] generatePath(int startX, int startY, int endX, int endY) {
_deltaX = Math.Abs(endX - startX);
_deltaY = Math.Abs(endY - startY);
if (_deltaX >=_deltaY) {
//x is independent variable
_numpixels = _deltaX + 1;
_d = (2 * _deltaY) - _deltaY;
_dinc1 = _deltaY << 1;
_dinc2 = (_deltaY - _deltaX) << 1;
_xinc1 = 1;
_xinc2 = 1;
_yinc1 = 0;
_yinc2 = 1;
} else {
//y is independent variable
_numpixels = _deltaY + 1;
_d = (2 * _deltaX) - _deltaY;
_dinc1 = _deltaX << 1;
_dinc2 = (_deltaX - _deltaY) << 1;
_xinc1 = 0;
_xinc2 = 1;
_yinc1 = 1;
_yinc2 = 1;
}
// Make sure x and y move in the right directions
if (startX > endX) {
_xinc1 = -_xinc1;
_xinc2 = -_xinc2;
}
if (startY > endY) {
_yinc1 = -_yinc1;
_yinc2 = -_yinc2;
}
_x = startX;
_y = startY;
Point[] returnPath = new Point[_numpixels];
for (int i = 0;i < _numpixels;i++) {
returnPath[i].X =_x;
returnPath[i].Y =_y;
if (_d < 0) {
_d = _d + _dinc1;
_x = _x + _xinc1;
_y = _y + _yinc1;
} else {
_d = _d + _dinc2;
_x = _x + _xinc2;
_y = _y + _yinc2;
}
}
return returnPath;
}
방법을 두 점을 변형 :
을
public static double GetLenghtBetweenPoints(Point Source, Point Distination) {
return Math.Sqrt((Math.Pow((Source.X-Distination.X), 2) + Math.Pow((Source.Y-Distination.Y), 2)));
}
@Italy, 내 수학은 덤프입니다. 나는 선의 방정식을 만드는 법을 모른다. 더 많은 힌트 pls? – VOX
@VOX : Google에 시도 했습니까? –
예. 지금까지, phew ... – VOX