(C+;+;)夹紧圆内的二维位置(使用中点圆算法绘制) 我现在用C++程序中的中点圆算法画圆。下面是我正在使用的代码示例 void drawcircle(int x0, int y0, int radius) { int x = radius-1; int y = 0; int dx = 1; int dy = 1; int err = dx - (radius << 1); while (x >= y) { putpixel(x0 + x, y0 + y); putpixel(x0 + y, y0 + x); putpixel(x0 - y, y0 + x); putpixel(x0 - x, y0 + y); putpixel(x0 - x, y0 - y); putpixel(x0 - y, y0 - x); putpixel(x0 + y, y0 - x); putpixel(x0 + x, y0 - y); if (err <= 0) { y++; err += dy; dy += 2; } if (err > 0) { x--; dx += 2; err += (-radius << 1) + dx; } } }

(C+;+;)夹紧圆内的二维位置(使用中点圆算法绘制) 我现在用C++程序中的中点圆算法画圆。下面是我正在使用的代码示例 void drawcircle(int x0, int y0, int radius) { int x = radius-1; int y = 0; int dx = 1; int dy = 1; int err = dx - (radius << 1); while (x >= y) { putpixel(x0 + x, y0 + y); putpixel(x0 + y, y0 + x); putpixel(x0 - y, y0 + x); putpixel(x0 - x, y0 + y); putpixel(x0 - x, y0 - y); putpixel(x0 - y, y0 - x); putpixel(x0 + y, y0 - x); putpixel(x0 + x, y0 - y); if (err <= 0) { y++; err += dy; dy += 2; } if (err > 0) { x--; dx += 2; err += (-radius << 1) + dx; } } },c++,geometry,trigonometry,angle,clamp,C++,Geometry,Trigonometry,Angle,Clamp,要确定一个点是否在圆中,首先需要计算它与圆中心的距离,这里是(100100)。 大概是这样的: #include <math.h> //for pow and sqrt double getPointDistance(int x, int y) { return sqrt (pow ((circleCenterX - x), 2.0) + pow ((circleCenterY - y), 2.0)); } bool isInCircle(int x,

要确定一个点是否在圆中,首先需要计算它与圆中心的距离,这里是(100100)。 大概是这样的:

#include <math.h> //for pow and sqrt

double getPointDistance(int x, int y) {
    return sqrt (pow ((circleCenterX - x), 2.0) + 
        pow ((circleCenterY - y), 2.0));
}
bool isInCircle(int x, int y) {
    if (circleRadius >= getPointDistance(x, y)) {
        //it's inside the circle (we assumed on the edge is inside)
        return true;
    } else {
        //given point is outside of the circle
        return false;
    }
}

x,y应满足方程(x-xo)^2+(y-y0)^2
bool isInCircle(int x, int y) {
    if (circleRadius >= getPointDistance(x, y)) {
        //it's inside the circle (we assumed on the edge is inside)
        return true;
    } else {
        //given point is outside of the circle
        return false;
    }
}