Win32 GDI - Practice (I) Draw Arc with Two Points and Arc Radius

How to Draw a Arc with AngelArc Function in GDI? if we just have two Node points of  the Arc and the Arc Radius?

We can calculate the Arc Center with Math formula directly~ but it seems too complicate for some of us(sepecially for me, I almost take several hours to work out the center point axis). check the code below would be good for us to do so, and give my thanks to whoever help me in the internet.:

static bool calCenterPoint(double x1, double y1, double x2, double y2, double x3, double y3, double r, double* xC, double* yC) {
 //POINT (x3,y3) is the control point to get the correct point.
 double dx = 0.5*(y1-y2);
 double dy = 0.5*(x2-x1);
 double R = dx*dx+dy*dy;
 double x[2];
 double y[2];
 if( R<0.0000001 || r*r<R )
  return false;
    r = sqrt(r*r-R)/sqrt(R);  
 dx *= r;  
 dy *= r;  
 x[0] = 0.5*(x1+x2)+dx;
 y[0] = 0.5*(y1+y2)+dy;
 x[1] = 0.5*(x1+x2)-dx;
 y[1] = 0.5*(y1+y2)-dy;
 
 double dDisTo3A = (y[0] - y3) * (y[0] - y3) + (x[0] - x3) * (x[0] - x3);
 double dDisTo3B = (y[1] - y3) * (y[1] - y3) + (x[1] - x3) * (x[1] - x3);
 if(dDisTo3A > dDisTo3B)
 {
  *xC = x[0];
  *yC = y[0];
 }
 else
 {
  *xC = x[1];
  *yC = y[1];
 }
 return   true;  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值