高分求助!用求逼近点的方法来画椭圆和圆弧

hardstudylulin 2003-02-20 01:10:30
不用CDC类库中的画椭圆和圆弧的函数来画,而是求出椭圆和圆上的逼近点,然后连接各个逼点形成椭圆和圆弧!
如有算法或现成的例子,请发到:hardlulin@163.com
万分感谢!
...全文
66 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
hailong0108 2003-02-21
  • 打赏
  • 举报
回复
用这个方程:
先定出每一段的长度。由半径及长度就可求出每次所转的角度, 在做个函数求每一点绕圆心旋转所成的点;
大体思路就是这样的。你在整理一下。
我给你一个旋转函数。
/**********************************************************************************
名称: 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;
sevencat 2003-02-21
  • 打赏
  • 举报
回复
呵呵,又晚了。
hardstudylulin 2003-02-20
  • 打赏
  • 举报
回复
TO:Sevencat
请问能不能用这种方法,实现按给出的角度来画圆弧!谢谢!
demetry 2003-02-20
  • 打赏
  • 举报
回复
good
sevencat 2003-02-20
  • 打赏
  • 举报
回复
BRESHMAN有这个算法的,只要讲图像算法的书上都会有的。我贴一下吧,包括画线的。
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同乘以一个比值(浮点数),那么这个函数就可以用来画椭圆
azhuguang 2003-02-20
  • 打赏
  • 举报
回复
学习!
hailong0108 2003-02-20
  • 打赏
  • 举报
回复
这个不太容易,查一查图形算法的书吧。
zswzwy 2003-02-20
  • 打赏
  • 举报
回复
搜一下吧。

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧