解决方案 »
- 隐藏鼠标的实现
- 这两者有啥区别?
- 为什么我在调用GetDefaultPrinter时会出error C2065: 'GetDefaultPrinter' : undeclared identifier
- IGES文件中的有理B样条曲面怎么和OPENGL中的gluNurbsSurface函数相关联
- 虚拟pc原理
- 50求菜鸟级问题。。。急!!!
- 如何设置Ctrl+QA型热键?,删除D:\aaa目录的函数是什么?
- 推荐几本关于介绍算法的好书。
- oralce连接(哪位大哥有这样的实验)
- 有没有哪位大虾用过activeskin.ocx?
- 发现MFC的BUG...
- 我一在OnNewDocument函数内设断点就出现断言错误
void b_line (int x1, int y1, int x2, int y2, char color)
{
register int i,sum;
int dx,dy,wc_x=0,wc_y=0,increment_x,increment_y;
dx=x2-x1;
if(dx>0) increment_x=1;
else if(dx==0) increment_x=0;
else {increment_x=-1;dx=-dx;}
dy=y2-y1;
if(dy>0) increment_y=1;
else if(dy==0) increment_y=0;
else {increment_y=-1;dy=-dy;}
if(dx>dy) sum=dx;
else sum=dy;
for (i=0;i<=sum+1;i++)
{
point(x1,y1,color); // 画点函数
wc_x+=dx;wc_y+=dy;
if(wc_x>sum)
{ wc_x-=sum;
x1+=increment_x;}
if(wc_y>sum)
{ wc_y-=sum;
y1+=increment_y;}
}
}
void b_circle(int x0,int y0,int r,char color)
{
register int x,y,increment;
int startx,endx,starty,endy,i;
y=r;
increment=3-2*r;
for(x=0;x<y;)
{
startx=x;endx=x+1;
starty=y;endy=y+1;
for(i=startx;i<endx;++i)
{point(x0+i,y0+y,color); // 画点函数
point(x0+i,y0-y,color);
point(x0-i,y0-y,color);
point(x0-i,y0+y,color);
}
for(i=starty;i<endy;++i)
{point(x0+i,y0+x,color);
point(x0+i,y0-x,color);
point(x0-i,y0-x,color);
point(x0-i,y0+x,color);
}
if(increment<0) increment+=4*x+6;
else {increment+=4*(x-y)+10;y--;}
x++;
} x=y;
if(y)
{startx=x;endx=x+1;
starty=y;endy=y+1;
for(i=startx;i<endx;++i)
{point(x0+i,y0+y,color);
point(x0+i,y0-y,color);
point(x0-i,y0-y,color);
point(x0-i,y0+y,color);
}
for(i=starty;i<endy;++i)
{point(x0+i,y0+x,color);
point(x0+i,y0-x,color);
point(x0-i,y0-x,color);
point(x0-i,y0+x,color);
}
}
}
如果将startx、endx、starty、endy同乘以一个比值(浮点数),那么这个函数就可以用来画椭圆
请问能不能用这种方法,实现按给出的角度来画圆弧!谢谢!
先定出每一段的长度。由半径及长度就可求出每次所转的角度, 在做个函数求每一点绕圆心旋转所成的点;
大体思路就是这样的。你在整理一下。
我给你一个旋转函数。
/**********************************************************************************
名称: Rotate()
时间: 2003.1.20
参数: point1 要转的点,pointCenter 旋转中心。Angle 旋转角(弧度) + 为逆时针 - 顺时针
返回值:point
说明: 求绕某点的旋转点
/************************************************************************************/void Rotate(CPoint point1,CPoint pointCenter,double Angle,CPoint& point)
{
Angle = Angle*180/3.1415926;
double O1,O;
O1=atan(fabs((double)(point1.y - pointCenter.y)/(point1.x - pointCenter.x)));//#include <math.h>
//判断两点的相对位置
//在坐标轴上的情况
if(point1.y == pointCenter.y && point1.x > pointCenter.x) //0度角
{
O1 = 0;
}
else if(point1.y > pointCenter.y && point1.x == pointCenter.x) //90度角
{
O1 = 90;
}
else if(point1.y == pointCenter.y && point1.x < pointCenter.x) //180度角
{
O1 = 180;
}
else if(point1.y < pointCenter.y && point1.x ==pointCenter.x) //270度角
{
O1 = 270;
}
else if(point1.x > pointCenter.x && point1.y > pointCenter.y) //the first quadrant
{
O1 = O1*180/3.1415926;
}
else if(point1.x < pointCenter.x && point1.y > pointCenter.y) //the secondly quadrant
{
O1 = 180-O1*180/3.1415926;
}
else if(point1.x < pointCenter.x && point1.y < pointCenter.y) //the third quadrant
{
O1= 180+O1*180/3.1415926;
}
else //the forthly quadrant
{
O1= 360-O1*180/3.1415926;
}
double L=sqrt((point1.x - pointCenter.x)*(point1.x - pointCenter.x)+(point1.y - pointCenter.y)*(point1.y - pointCenter.y));
O=(O1-Angle)/180*3.1415926;
point.x = (long)(pointCenter.x + L*cos(O));//加入#include <math.h>
point.y = (long)(pointCenter.y + L*sin(O));
}椭圆用这个方程:
x(t) = (ax* t*t + bx * t + cx)/(1 + t*t)
y(t) = (ay* t*t + by * t + cy)/(1 + t*t)
t[0,1];的参数
cx = x0;
cy = y0;
bx = -2*x0 + 2* x1;
by = -2*y0 + 2* y1;
ax = x0 -2*x1 + 2*x2;
ay = y0 -2*y1 + 2*y2;
第一点 x0,y0;
第二点 x1,y1;
第三点 x2,y2;