여기 참고 해서 php용으로 만들었습니다.
그런데 결과물은 php내장함수와 거의 똑같네요.
좀 다를 줄 알았는데......
php 내장함수를 사용하지 않고 원이나 타원 직선을 그릴수 있는 정도에 만족해야 할듯합니다.
알고리즘에 대한 설명은 없습니다.
test.php
-----------------------------------------------------------------------------------------------------------------------------
<?php
//직선 그리기
function imageline_bresenham(& $im, $startX, $startY, $endX, $endY, $color){
//기준점 계산, 작은 쪽이 출발점, 큰쪽이 도착점
if($endX < $startX){
$dx = $startX - $endX;
$tmpX = $endX;
$tmpgoX = $startX;
}
else{
$dx = $endX - $startX;
$tmpX = $startX;
$tmpgoX = $endX;
}
if($endY < $startY){
$dy = $startY - $endY;
$tmpY = $endY;
$tmpgoY = $startY;
}
else{
$dy = $endY - $startY;
$tmpY = $startY;
$tmpgoY = $endY;
}
/* 기울기에 따른 계산*/
if($dx >= $dy) { //기울기가 1보다 작거나 같을때
$d = $dy * 2 - $dx; //d의 값을 초기화
$incrE = $dy * 2; // E로의 이동을 위해서 쓰이는 증가
$incrNE = ($dy - $dx) * 2; // NE로의 이동을 위해서 쓰이는 증가
$start = $tmpX;
$end = $tmpgoX;
}
else { //기울기가 1보다 클때
$d = $dx * 2 - $dy;
$incrE = $dx * 2;
$incrNE = ($dx - $dy) * 2;
$start = $tmpY;
$end = $tmpgoY;
}
//x, y 좌표 초기화
$x = $startX;
$y = $startY;
imagesetpixel($im, $x, $y, $color);//시작점 찍음
while($start < $end) {
if( $d <= 0) { /*D값이 0보다 작으면 E를 선택 하나의 축만 이동*/
$d += $incrE;
if($dx >= $dy) { // 기울기가 1보다 작을때 X좌표만 증가
if($endX < $startX)
$x--;
else
$x++;
}
else { // 기울기가 1보다 클때 Y좌표만 증가
if($endY < $startY)
$y--;
else
$y++;
}
}
else { /*D값이 0보다 클때 NE를 선택 X,Y 를 같이 이동시킨다.*/
$d += $incrNE;
if($endX < $startX)
$x--;
else
$x++;
if($endY < $startY)
$y--;
else
$y++;
}
imagesetpixel($im, $x, $y, $color);
$start ++;
}
}
function imagearc_bresenham(& $im, $centerX, $centerY, $width, $height, $color) {
$w_r = ceil($width / 2);
$h_r = ceil($height / 2);
$x = 0;
$y = $h_r;
$w_r_square = $w_r * $w_r;
$h_r_square = $h_r * $h_r;
$d = (4 * $h_r_square + $w_r_square * (1 - (4 * $h_r))) / 4;
imagesetpixel($im, $x + $centerX, $y + $centerY, $color);
imagesetpixel($im, $centerX - $x, $y + $centerY, $color);
imagesetpixel($im, $x + $centerX, $centerY - $y , $color);
imagesetpixel($im, $centerX - $x, $centerY - $y, $color);
// $x 독립변수 구간
while($h_r_square * $x < $w_r_square * $y){
++$x;
if($d < 0){
$d += $h_r_square * (2 * $x + 1);
}
else {
--$y;
$d += $h_r_square * (2 * $x + 1) - (2 * $w_r_square * $y);
}
imagesetpixel($im, $x + $centerX, $y + $centerY, $color);
imagesetpixel($im, $centerX - $x, $y + $centerY, $color);
imagesetpixel($im, $x + $centerX, $centerY - $y, $color);
imagesetpixel($im, $centerX - $x, $centerY - $y, $color);
}
// $y 독립변수 구간
$x = $w_r;
$y = 0;
$d = (4 * $w_r_square + $h_r_square * (1 - (4 * $w_r))) / 4;
imagesetpixel($im, $x + $centerX, $y + $centerY, $color);
imagesetpixel($im, $centerX - $x, $y + $centerY, $color);
imagesetpixel($im, $x + $centerX, $centerY - $y, $color);
imagesetpixel($im, $centerX - $x, $centerY - $y, $color);
while($h_r_square * $x > $w_r_square * $y){
++$y;
if($d < 0){
$d += $w_r_square * (2 * $y + 1);
}
else {
--$x;
$d += $w_r_square * (2 * $y + 1) - (2 * $h_r_square * $x);
}
imagesetpixel($im, $x + $centerX, $y + $centerY, $color);
imagesetpixel($im, $centerX - $x, $y + $centerY, $color);
imagesetpixel($im, $x + $centerX, $centerY - $y, $color);
imagesetpixel($im, $centerX - $x, $centerY - $y, $color);
}
}
$w = 400;
$h = 800;
$im = imagecreatetruecolor($w, $h);
$red = imagecolorallocate($im, 255, 0, 0);
imageline_bresenham($im, 200, 200, 100, 0, $red);
imageline_bresenham($im, 200, 200, 400, 100, $red);
imageline_bresenham($im, 200, 200, 400, 200, $red);
imageline_bresenham($im, 200, 200, 400, 300, $red);
imagearc_bresenham($im, 200, 200, 180, 360, $red);
imagearc_bresenham($im, 100, 200, 200, 200, $red);
imageline($im, 200, 600, 100, 400, $red);
imageline($im, 200, 600, 400, 500, $red);
imageline($im, 200, 600, 400, 600, $red);
imageline($im, 200, 600, 400, 700, $red);
imagearc($im, 200, 600, 180, 360, 0, 360, $red);
imagearc($im, 100, 600, 200, 200, 0, 360, $red);
header('Content-Type: image/png');
imagepng($im);
?>
샘플 : http://apmusers.com/php_arc.php
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 1930 | 17년 전 | 3001 | ||
| 1929 | 17년 전 | 1878 | ||
| 1928 | 17년 전 | 3992 | ||
| 1927 | 17년 전 | 1409 | ||
| 1926 |
지엔소프트
|
17년 전 | 1126 | |
| 1925 |
보드타는찌니
|
17년 전 | 1243 | |
| 1924 |
choijinhee
|
17년 전 | 1126 | |
| 1923 | 17년 전 | 1388 | ||
| 1922 | 17년 전 | 1746 | ||
| 1921 | 17년 전 | 2337 | ||
| 1920 | 17년 전 | 2415 | ||
| 1919 | 17년 전 | 1418 | ||
| 1918 | 17년 전 | 1168 | ||
| 1917 | 17년 전 | 2437 | ||
| 1916 | 17년 전 | 2869 | ||
| 1915 |
|
17년 전 | 3232 | |
| 1914 | 17년 전 | 3171 | ||
| 1913 | 17년 전 | 2338 | ||
| 1912 | 17년 전 | 3754 | ||
| 1911 | 17년 전 | 3184 | ||
| 1910 | 17년 전 | 5505 | ||
| 1909 | 17년 전 | 2655 | ||
| 1908 | 17년 전 | 1859 | ||
| 1907 | 17년 전 | 1934 | ||
| 1906 | 17년 전 | 1775 | ||
| 1905 | 17년 전 | 1706 | ||
| 1904 | 17년 전 | 2767 | ||
| 1903 | 17년 전 | 1893 | ||
| 1902 | 17년 전 | 1581 | ||
| 1901 | 17년 전 | 2071 | ||
| 1900 |
stuartkim
|
17년 전 | 1137 | |
| 1899 | 17년 전 | 1667 | ||
| 1898 | 17년 전 | 2882 | ||
| 1897 | 17년 전 | 2126 | ||
| 1896 | 17년 전 | 1820 | ||
| 1895 | 17년 전 | 2036 | ||
| 1894 | 17년 전 | 1324 | ||
| 1893 | 17년 전 | 1716 | ||
| 1892 | 17년 전 | 1214 | ||
| 1891 | 17년 전 | 1776 | ||
| 1890 | 17년 전 | 1804 | ||
| 1889 | 17년 전 | 1040 | ||
| 1888 | 17년 전 | 3136 | ||
| 1887 | 17년 전 | 4316 | ||
| 1886 | 17년 전 | 2462 | ||
| 1885 | 17년 전 | 7472 | ||
| 1884 | 17년 전 | 3835 | ||
| 1883 | 17년 전 | 4167 | ||
| 1882 | 17년 전 | 2425 | ||
| 1881 | 17년 전 | 2888 | ||
| 1880 | 17년 전 | 3638 | ||
| 1879 | 17년 전 | 4005 | ||
| 1878 | 17년 전 | 3165 | ||
| 1877 | 17년 전 | 3147 | ||
| 1876 | 17년 전 | 3294 | ||
| 1875 | 17년 전 | 2462 | ||
| 1874 | 17년 전 | 2058 | ||
| 1873 | 17년 전 | 3109 | ||
| 1872 | 17년 전 | 3258 | ||
| 1871 | 17년 전 | 4610 | ||
| 1870 | 17년 전 | 1592 | ||
| 1869 | 17년 전 | 2616 | ||
| 1868 | 17년 전 | 2689 | ||
| 1867 | 17년 전 | 1900 | ||
| 1866 | 17년 전 | 2220 | ||
| 1865 | 17년 전 | 1837 | ||
| 1864 | 17년 전 | 2371 | ||
| 1863 | 17년 전 | 3776 | ||
| 1862 | 17년 전 | 3895 | ||
| 1861 | 17년 전 | 2080 | ||
| 1860 | 17년 전 | 1360 | ||
| 1859 | 17년 전 | 1496 | ||
| 1858 |
|
17년 전 | 1649 | |
| 1857 | 17년 전 | 1632 | ||
| 1856 |
보드타는찌니
|
17년 전 | 1397 | |
| 1855 | 17년 전 | 1543 | ||
| 1854 |
|
17년 전 | 1360 | |
| 1853 | 17년 전 | 1849 | ||
| 1852 | 17년 전 | 2749 | ||
| 1851 | 17년 전 | 1849 | ||
| 1850 |
|
17년 전 | 1403 | |
| 1849 |
|
17년 전 | 1690 | |
| 1848 |
|
17년 전 | 2329 | |
| 1847 | 17년 전 | 1943 | ||
| 1846 |
은사시나무
|
17년 전 | 1264 | |
| 1845 |
갈색야생마
|
17년 전 | 5904 | |
| 1844 |
갈색야생마
|
17년 전 | 3282 | |
| 1843 |
갈색야생마
|
17년 전 | 3178 | |
| 1842 |
갈색야생마
|
17년 전 | 2589 | |
| 1841 |
갈색야생마
|
17년 전 | 2770 | |
| 1840 |
갈색야생마
|
17년 전 | 2719 | |
| 1839 |
갈색야생마
|
17년 전 | 3226 | |
| 1838 |
갈색야생마
|
17년 전 | 2353 | |
| 1837 |
갈색야생마
|
17년 전 | 2471 | |
| 1836 |
갈색야생마
|
17년 전 | 2532 | |
| 1835 |
갈색야생마
|
17년 전 | 2525 | |
| 1834 |
갈색야생마
|
17년 전 | 2666 | |
| 1833 |
갈색야생마
|
17년 전 | 3188 | |
| 1832 |
갈색야생마
|
17년 전 | 2701 | |
| 1831 |
갈색야생마
|
17년 전 | 1426 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기