여기 참고 해서 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
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 3030 | 14년 전 | 1170 | ||
| 3029 |
|
14년 전 | 1294 | |
| 3028 | 14년 전 | 1041 | ||
| 3027 | 14년 전 | 849 | ||
| 3026 | 14년 전 | 1036 | ||
| 3025 |
마케팅메지션
|
14년 전 | 1155 | |
| 3024 | 14년 전 | 862 | ||
| 3023 | 14년 전 | 848 | ||
| 3022 |
|
14년 전 | 1221 | |
| 3021 | 14년 전 | 1017 | ||
| 3020 | 14년 전 | 906 | ||
| 3019 | 14년 전 | 1060 | ||
| 3018 | 14년 전 | 1232 | ||
| 3017 |
마케팅메지션
|
14년 전 | 939 | |
| 3016 |
|
14년 전 | 973 | |
| 3015 | 14년 전 | 667 | ||
| 3014 | 14년 전 | 884 | ||
| 3013 | 14년 전 | 1094 | ||
| 3012 | 14년 전 | 925 | ||
| 3011 | 14년 전 | 924 | ||
| 3010 | 14년 전 | 1146 | ||
| 3009 |
마케팅메지션
|
14년 전 | 1659 | |
| 3008 | 14년 전 | 580 | ||
| 3007 | 14년 전 | 1018 | ||
| 3006 |
마케팅메지션
|
14년 전 | 1000 | |
| 3005 |
마케팅메지션
|
14년 전 | 896 | |
| 3004 | 14년 전 | 877 | ||
| 3003 |
마케팅메지션
|
14년 전 | 990 | |
| 3002 | 14년 전 | 776 | ||
| 3001 | 14년 전 | 2010 | ||
| 3000 | 14년 전 | 775 | ||
| 2999 | 14년 전 | 1669 | ||
| 2998 | 14년 전 | 759 | ||
| 2997 |
|
14년 전 | 848 | |
| 2996 | 14년 전 | 938 | ||
| 2995 | 14년 전 | 894 | ||
| 2994 | 14년 전 | 1598 | ||
| 2993 |
마케팅메지션
|
14년 전 | 1006 | |
| 2992 |
마케팅메지션
|
14년 전 | 961 | |
| 2991 |
마케팅메지션
|
14년 전 | 1131 | |
| 2990 | 14년 전 | 972 | ||
| 2989 | 14년 전 | 792 | ||
| 2988 |
|
14년 전 | 941 | |
| 2987 | 14년 전 | 817 | ||
| 2986 | 14년 전 | 1035 | ||
| 2985 | 14년 전 | 580 | ||
| 2984 | 14년 전 | 960 | ||
| 2983 | 14년 전 | 965 | ||
| 2982 | 14년 전 | 910 | ||
| 2981 | 14년 전 | 835 | ||
| 2980 |
마케팅메지션
|
14년 전 | 1171 | |
| 2979 |
마케팅메지션
|
14년 전 | 903 | |
| 2978 |
|
14년 전 | 844 | |
| 2977 |
|
14년 전 | 875 | |
| 2976 | 14년 전 | 818 | ||
| 2975 | 14년 전 | 816 | ||
| 2974 | 14년 전 | 896 | ||
| 2973 | 14년 전 | 1286 | ||
| 2972 | 14년 전 | 670 | ||
| 2971 | 14년 전 | 732 | ||
| 2970 | 14년 전 | 898 | ||
| 2969 | 14년 전 | 914 | ||
| 2968 | 14년 전 | 775 | ||
| 2967 | 14년 전 | 1354 | ||
| 2966 | 14년 전 | 856 | ||
| 2965 |
|
14년 전 | 1086 | |
| 2964 | 14년 전 | 1475 | ||
| 2963 | 14년 전 | 957 | ||
| 2962 |
|
14년 전 | 979 | |
| 2961 |
|
14년 전 | 886 | |
| 2960 | 14년 전 | 838 | ||
| 2959 | 14년 전 | 1183 | ||
| 2958 | 14년 전 | 934 | ||
| 2957 |
|
14년 전 | 815 | |
| 2956 |
|
14년 전 | 1195 | |
| 2955 |
|
14년 전 | 2342 | |
| 2954 | 14년 전 | 932 | ||
| 2953 | 14년 전 | 1052 | ||
| 2952 |
senseme
|
14년 전 | 1184 | |
| 2951 |
뱌미3059
|
14년 전 | 903 | |
| 2950 |
|
14년 전 | 950 | |
| 2949 | 14년 전 | 998 | ||
| 2948 | 14년 전 | 870 | ||
| 2947 |
|
14년 전 | 960 | |
| 2946 |
개발조각사
|
14년 전 | 2451 | |
| 2945 |
개발조각사
|
14년 전 | 1761 | |
| 2944 |
개발조각사
|
14년 전 | 6051 | |
| 2943 |
개발조각사
|
14년 전 | 1295 | |
| 2942 |
개발조각사
|
14년 전 | 1568 | |
| 2941 |
개발조각사
|
14년 전 | 1931 | |
| 2940 |
개발조각사
|
14년 전 | 3659 | |
| 2939 |
개발조각사
|
14년 전 | 2989 | |
| 2938 |
개발조각사
|
14년 전 | 2064 | |
| 2937 |
개발조각사
|
14년 전 | 1570 | |
| 2936 |
개발조각사
|
14년 전 | 4019 | |
| 2935 | 14년 전 | 1097 | ||
| 2934 | 14년 전 | 876 | ||
| 2933 | 14년 전 | 1051 | ||
| 2932 | 14년 전 | 980 | ||
| 2931 | 14년 전 | 978 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기