代码速记

16进制字符串转int型

unsigned long x=0;
CString strzHex = "430";
sscanf(strzHex,"%x",&x);

 

 

 

//lpMeasureItemStruct->itemHeight = 100;

//// Get the LOGFONT for the current font.
//LOGFONT lf;
//::ZeroMemory(&lf, sizeof(lf));

//CFont* pFont = GetFont();
//ASSERT_VALID(pFont);

//if (pFont)
// VERIFY(pFont->GetLogFont(&lf));

//int nAdj(4) ;
//m_nLinesPerRow = max(m_nLinesPerRow, 1);

//if (lf.lfHeight < 0)
// lpMeasureItemStruct->itemHeight = ((-lf.lfHeight+nAdj) * (m_nLinesPerRow));
//else
// lpMeasureItemStruct->itemHeight = ((lf.lfHeight+nAdj) * (m_nLinesPerRow));

//CListCtrl::OnMeasureItem(nIDCtl, lpMeasureItemStruct);

 

 

 

CBitmap bitmap;
int bitmapWidth;
int bitmapHeight;
BITMAP bm;
bitmap.LoadBitmap(IDB_BITMAPVideo);
bitmap.GetObject(sizeof(bm),&bm);
bitmapWidth=bm.bmWidth;
bitmapHeight=bm.bmHeight;

CDC dcMemory;
CRect rect;
GetClientRect(&rect);
dcMemory.CreateCompatibleDC(NULL);
dcMemory.SelectObject(&bitmap);
dc.StretchBlt(0,0,rect.right,rect.bottom,&dcMemory,
0,0,bitmapWidth,bitmapHeight,SRCCOPY);

 

 

 

 double x1=dbPrevCx,x2=dbVertexCx,y1=dbPrevCy,y2=dbVertexCy;
   double d=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
   double H=/*fabs(*/dbBulge*d/2/*)*/;
   double R=fabs((H*H+(d/2)*(d/2))/(2*H));
   double x = 0.00;
   double y = 0.00;

   double fR = 0.00;

   fR = asin(fabs(fabs(H)-R)/R);

   if(H<0 && fabs(H)<R || H>0 && fabs(H)>R)
    fR = 2*PI - fR;

   //角度<长度
   double tempfw=fangwei(x1,y1,x2,y2);
   //fR = (fR * PI) / 180;
   tempfw=fR -tempfw;

   x = x2-R*cos(tempfw);
   y = y2+R*sin(tempfw);

   double dbAsin = fabs(2*dbBulge / (pow(dbBulge,2)+1));
   //角度差(圆心角)
   double dbAngleCenter = fabs(2 * asin(dbAsin));

   /*大于180度弧*/
   if(fabs(H)>R)
    dbAngleCenter =  2*PI - dbAngleCenter;

   //计算两个向量的夹角公式

   double x0 = x+R,y0 = y;
   double dbStartAngle = 0.00;
   double dbLastAngle  = 0.00;
   double a1 = 0.00;
   double b1 = 0.00;
   double c1 = 0.00;
   double d1 = 0.00;

   if(dbBulge>-0.00000001)
   {
    a1 = x0-x;
    b1 = x1-x;
    c1 = y0-y;
    d1 = y1-y;

   }else if(dbBulge<0.00000001)
   {
    a1 = x0-x;
    b1 = x2-x;
    c1 = y0-y;
    d1 = y2-y;
   }

   double fA = sqrt((pow(a1,2)) + (pow(c1,2)) );
   double fB = sqrt((pow(b1,2)) +(pow(d1,2)) );

   dbStartAngle = acos( (a1*b1 + c1*d1) /(fA * fB));

   //判断是否是包弧在哪个象限上
   if(d1 < 0.00000001)
   {
    dbStartAngle = 2*PI - dbStartAngle;
   }

   dbLastAngle  = dbAngleCenter + dbStartAngle;

   //等分点距离
   int nSplitCount = 0;

   //求弧长:L=n*2πR/360
   nSplitCount = (dbAngleCenter/PI*180)* ( ( 2*PI*R)/360);
   nSplitCount = GetOsGlob()->GetCurManager()->E_DL(nSplitCount) / 10.0;
   if(nSplitCount<10)
    nSplitCount = 10;

   int ptIndex = 0;
   //平滑插入点
   if(dbBulge>-0.00000001)//逆时针
   {
    //start point
    ptIndex= pChunk->m_vectorPointArray.add();
    pChunk->point_SetXY(ptIndex,x1,y1);

    for ( int i=0; i<=nSplitCount; i++)
    {
     double dAngleTmp = dbStartAngle + (dbAngleCenter)/(nSplitCount)*i;
     double xTmp = x+R*cos(dAngleTmp);
     double yTmp = y+R*sin(dAngleTmp);

     ptIndex = pChunk->m_vectorPointArray.add();
     pChunk->point_SetXY(ptIndex,xTmp,yTmp); 
    }

    //end point
    ptIndex= pChunk->m_vectorPointArray.add();
    pChunk->point_SetXY(ptIndex,x2,y2);

   }
   else if(dbBulge<0.00000001)//顺时针
   {
    ptIndex= pChunk->m_vectorPointArray.add();
    pChunk->point_SetXY(ptIndex,x1,y1);

    for ( int i=0; i<=nSplitCount; i++)
    {
     double dAngleTmp = dbLastAngle - (dbAngleCenter)/(nSplitCount)*i;
     double xTmp = x+R*cos(dAngleTmp);
     double yTmp = y+R*sin(dAngleTmp);

     ptIndex = pChunk->m_vectorPointArray.add();
     pChunk->point_SetXY(ptIndex,xTmp,yTmp);
    }

    //end point
    ptIndex= pChunk->m_vectorPointArray.add();
    pChunk->point_SetXY(ptIndex,x2,y2);

   }
  }
  dbPrevCx=dbVertexCx;
  dbPrevCy=dbVertexCy;
 }//end of for

 if (bLineOrSide)//the polygon is closed.
 {
  m_Vertices.RemoveAt( m_Vertices.GetCount()-1);
 }

 

 

double fangwei(double xa, double ya, double xb, double yb)
 {
  double dx0,dy0,ta,dx,dy;
  ta=0.0;
  dx = xb - xa;
  if(dx==0)
   dx = .000001;
  dy = yb - ya;
  if(dy==0)
   dy = .000001;
  dx0=fabs(dx);
  dy0=fabs(dy);
  ta = atan2(dy0,dx0);
  if(ta<0.0001)
   ta=0.0;
  if(dy>0 && dx<0)
   ta = PI - ta;
  if(dy<0 && dx<0)
   ta = PI + ta;
  if(dy<0 && dx>0)
   ta = 2 * PI - ta;
  return(ta);
 }

 

 

 

 

 

 

#include "StdAfx.h"
#include "../Utility/Utility.h"
#include <math.h>

//实体标题
const CString g_StrEntitiesTitle[] = { "3DFACE","3DSOLID","ACAD_PROXY_ENTITY",
"ARC","ATTDEF","ATTRIB","BODY","CIRCLE",
"DIMENSION", "ELLIPSE","HATCH","IMAGE",
"INSERT","LEADER","LINE","LWPOLYLINE",
"MLINE","MTEXT","OLEFRAME","OLE2FRAME",
"POINT","POLYLINE","RAY","REGION","SEQEND",
"SHAPE","SOLID","SPLINE","TABLE","TEXT",
"TOLERANCE","TRACE","VERTEX","VIEWPORT",
"WIPEOUT","XLINE"};

//线宽固定数组
const int nAryWidth[] =
{-3,-2,-1,0,5,9,13,15,18,20,25,30,35,40,50,53,60,70,80,90,100,106,120,140,158,200,211,99999};//99999表示最大为假值的情况

const CString sAryWidth[] =
{"KQ_DEFAULT","KQ_BYBLOCK","KQ_BYLAYER","0.001","0.05","0.09","0.13","0.15","0.18","0.2","0.25","0.3","0.35","0.4","0.5","0.53","0.6","0.7","0.8","0.9","1.0","1.06","1.2","1.4","1.58","2.0","2.11","KQ_ERROR"};

BOOL FindEntitiesTitle(CString strTxt)
{
 int nSize = sizeof(g_StrEntitiesTitle)/sizeof(CString);
 for (int n = 0;n<nSize;n++)
 {
  if(g_StrEntitiesTitle[n].CompareNoCase(strTxt) == 0)
  {
   return TRUE;
  }
 }
 return FALSE;
}
BOOL GetLineOrSide(BOOL&/*[out]*/ bLineOrSide,int nFlag)
{
 UCHAR cFlag = static_cast<char>(nFlag);
 /*多段线标志(按位编码;默认值 = 0):             (线)

 1 = 这是一个闭合多段线(或按 M 方向闭合的多边形网格)  (面)

 2 = 已添加曲线拟合顶点                                 (线)

 4 = 已添加样条曲线拟合顶点                             (线)

 8 = 这是一条三维多段线                                 (线)

 16 = 这是一个三维多边形网格                            (面)

 32 = 多边形网格以 N 方向闭合                           (面)

 64 = 多段线是一个多面网格                      (面)

 128 = 线型图案在该多段线顶点的周围连续生成             (线)*/

 //------------------------
 if( ((nFlag%2) >= 1) || (nFlag>=16 && nFlag<=127) )
  bLineOrSide = TRUE;
 else if(nFlag>128){
  int nFlagTmp = nFlag - 128;
  if(nFlagTmp>=16 && nFlagTmp<=127)
   bLineOrSide = TRUE;
 }
 else
  bLineOrSide = FALSE;

 return TRUE;
}
//解析线宽枚举 (为了解释其精确度实值宽度将比CAD值大 单位:1)
CString GetWidthForCADEnum(int nWidth)
{
 //线宽枚举以层为先
 //默认值为-3
 //随层没有
 //随块为-2
 int n = 0;
 for (;n<sizeof(nAryWidth)/sizeof(int);n++)
  if(nAryWidth[n] == nWidth)break;
 return sAryWidth[n];

}
CString COLORREFToString(COLORREF nColor)
{
 ASSERT(nColor <= RGB(255,255,255));
 if(nColor == RGB(255,255,255))
  return CString(_T("0,0,0"));
 CString strTmp(_T(""));
 strTmp.Format("%d,%d,%d",GetRValue(nColor),GetGValue(nColor),GetBValue(nColor));
 return strTmp;
}
/////////////////////////////////////////// 
//求三角形外接圆圆心坐标
/////////////////////////////////////////// 

void CalculateOuterCircle(double &X0,double &Y0, double &R,double SaveX[],double SaveY[])
{
 //取出三点坐标
 //*************************   外接圆   *******************//
 //前pt1,pt2不垂直pt3,pt2也不垂直
 if (SaveX[2] != SaveX[1] && SaveX[0] != SaveX[1] /*&& SaveX[0] != SaveX[2]*/)
 {
  double x1=(SaveX[0] + SaveX[1])/2.0;//求出第一个边垂直平分点
  double y1=(SaveY[0] + SaveY[1])/2.0;
  double x2=(SaveX[1] + SaveX[2])/2.0;//求出第二个边垂直平分点
  double y2=(SaveY[1] + SaveY[2])/2.0;
  double xx=(SaveX[0]-SaveX[1]);
  double yy=(SaveY[0]-SaveY[1]);
  double k1 =yy/xx;//第一条边的斜率
  //第一条边斜率为0,圆心X坐标已经知道,再求第二条垂线
  if (k1 == 0)
  {
   xx=(SaveX[2] - SaveX[1]);
   yy=(SaveY[2] - SaveY[1]);
   double k2 = yy/xx;//第二条边的斜率
   //求出垂线参数b
   //垂线方程y = -1/k2 * x + b;
   //经过垂足点
   double b21 =  y2 + x2/k2;
   X0 = x1;
   //经过圆心
   Y0 = -X0/k2 +b21;
   R =  sqrt( pow((X0 - SaveX[0]),2) + pow((Y0 - SaveY[0]),2) );
  }
  //第一条边斜率不为0
  else
  {
   double b11 = y1 + x1/k1;//求出第一条垂线参数b
   xx=(SaveX[2] - SaveX[1]);
   yy=(SaveY[2] - SaveY[1]);
   double k2 = yy/xx;//第二条边的斜率
   if (k2 == 0)
   {
    X0 = x2;
    Y0 = -X0/k1 +b11;
    R =  sqrt( pow((X0 - SaveX[0]),2) + pow((Y0 - SaveY[0]),2) );
   }
   else
   {
    //求出第二条垂线参数b
    double b21 = y2 + x2/k2;
    //求出两条直线焦点坐标
    X0 = (b21 - b11)/((-1/k1) - (-1/k2));
    Y0 = -X0/k1 +b11;
    R = sqrt( pow((X0 - SaveX[0]),2) + pow((Y0 - SaveY[0]),2) );

   }
  }
 }
 //pt3与pt2垂直
 else if (SaveX[2] == SaveX[1])
 {
  double x1=(SaveX[0] + SaveX[1])/2.0;//求出第一个线段垂直平分点
  double y1=(SaveY[0] + SaveY[1])/2.0;
  double x2=(SaveX[1] + SaveX[2])/2.0;//求出第二个线段垂直平分点
  double y2=(SaveY[1] + SaveY[2])/2.0;
  double xx=(SaveX[0]-SaveX[1]);
  double yy=(SaveY[0]-SaveY[1]);
  double k1 =yy/xx;//第一条边的斜率
  if (k1 == 0)
  {
   X0=(SaveX[0] + SaveX[2])/2.0;//
   Y0=(SaveY[0] + SaveY[2])/2.0;
   R =  sqrt( pow((X0 - SaveX[0]),2) + pow((Y0 - SaveY[0]),2) );
  }
  else
  {
   double b11 = y1 + x1/k1;
   X0 = (b11 - y2)*k1;
   Y0 = y2;
   R =  sqrt( pow((X0 - SaveX[0]),2) + pow((Y0 - SaveY[0]),2) );
  }
 }
 //pt1与pt2垂直
 else if (SaveX[0] == SaveX[1])
 {
  double x1=(SaveX[0] + SaveX[1])/2.0;//求出第一个线段垂直平分点
  double y1=(SaveY[0] + SaveY[1])/2.0;
  double x2=(SaveX[1] + SaveX[2])/2.0;//求出第二个线段垂直平分点
  double y2=(SaveY[1] + SaveY[2])/2.0;
  double xx=(SaveX[2] - SaveX[1]);
  double yy=(SaveY[2] - SaveY[1]);
  double k2 = yy/xx;//第二条边的斜率
  if (k2 == 0)
  {
   X0=(SaveX[0] + SaveX[2])/2.0;//
   Y0=(SaveY[0] + SaveY[2])/2.0;
   R =  sqrt( pow((X0 - SaveX[0]),2) + pow((Y0 - SaveY[0]),2) );
  }
  else
  {
   double b2 = y2 + x2/k2;
   Y0 = y1;
   X0 = (b2-Y0)*k2;
   R =  sqrt( pow((X0 - SaveX[0]),2) + pow((Y0 - SaveY[0]),2) );
  }
 }
}

void lwpolylineToArc(double BeginPoint_x,double BeginPoint_y,double EndPoint_x,double EndPoint_y,double u,double &CenterPoint_x,double &CenterPoint_y)
{
 double PI = 3.1415926;
 double centerAngle;//包角
 centerAngle=4*atan(abs(u));
 centerAngle=centerAngle/PI;

 double x1,x2,y1,y2;//圆弧起始点和终止点
 x1=BeginPoint_x;
 x2=EndPoint_x;
 y1=BeginPoint_y;
 y2=EndPoint_y;

 double L; //弦长
 L=sqrt(pow((x1-x2),2)+pow((y1-y2),2));

 double R;//圆弧半径
 R=0.5*L/sin(0.5*centerAngle);

 //已知圆上两点和半径,求圆心坐标
 double h;//圆心到弦的距离
 h=sqrt(R*R-L*L/4);

 double k;//起始点和终止点连线的中垂线斜率
 double xc,yc;//圆心坐标
 double xa,ya; //起始点和终止点连线的中点横纵坐标
 xa=0.5*(x1+x2);
 ya=0.5*(y1+y2);

 //弦的方向角(0-2PI之)

 double angle;//起点到终点的弦向量与x正方向之间的倾斜角
 angle=acos((x2-x1)/sqrt(pow(x2-x1,2)+pow(y2-y1,2)));

 double amass; //弦向量与X轴正向单位向量的叉积
 amass = y1-y2;//由(由(x2-x1)*0-1*(y2-y1))得到

 if (amass<0)
 {  angle=-angle;
 angle=2*PI+angle;
 }

 double DirectionAngle;//弦中点到圆心的直线向量的方向角(0-2PI之间)
 if ((u>0 && centerAngle<PI)||(u<0 && centerAngle>PI))
  DirectionAngle=angle+PI/2;
 if((u<0 && centerAngle<PI)||(u>0 && centerAngle>PI))
  DirectionAngle=angle-PI/2;
 if (DirectionAngle>2*PI)
  DirectionAngle= DirectionAngle-2*PI;

 double d;//圆心到弦的距离
 d=sqrt(R*R-L*L/4);
 if (DirectionAngle=0)
 {
  xc=xa+d;
  yc=ya;
 }
 else if(DirectionAngle=PI/2)
 {
  xc=xa;
  yc=ya+d;
 }
 else if (DirectionAngle=PI)
 {
  xc=xa-d;
  yc=xa;
 }
 else if (DirectionAngle=PI+PI/2)
 {
  xc=xa;
  yc=xa-d;
 }
 else
 {
  double nslope,k;//nslope 为弦的斜率,K为弦中垂线的斜率
  double nAngle;//中垂线的倾斜角;
  double X,Y; //圆心相对于弦中心点的坐标偏移量

  nslope = (y2 - y1) / (x2-x1);
  k = -1 / nslope;
  nAngle = atan(k) ;
  X = cos(nAngle) * d;
  Y = sin(nAngle) * d;

  if (DirectionAngle > PI / 2 && DirectionAngle < PI )
  {X = -X;
  Y = -Y;
  }
  if (DirectionAngle > PI && DirectionAngle < (PI + PI / 2) )
  {
   X = -X;
   Y = -Y;
  }

  xc=xa + X;
  yc=ya+ Y;

  CenterPoint_x=xc;
  CenterPoint_y=yc;
  //CenterPoint.z=0.0;

 }
}

double diameter(double Ax, double Ay, double Bx, double By, double Cx, double Cy,double&x,double&y)
{       
 double a = Ax;
 double b = Bx;
 double c = Cx;
 double m = Ay;
 double n = By;
 double k = Cy;
 double A = a*b*b + a*n*n + a*a*c - b*b*c + m*m*c - n*n*c - a*c*c - a*k*k - a*a*b +b*c*c - m*m*b + b*k*k;
 double B = a*n + m*c + k*b - n*c - a*k - b*m;
 y = A/B/2;
 double AA = b*b*m + m*n*n + a*a*k - b*b*k + m*m*k -n*n*k -c*c*m -m*k*k -a*a*n +c*c*n -m*m*n + k*k*n;
 double BB = b*m + a*k + c*n - b*k - c*m - a*n;
 x = AA/BB/2;
 return sqrt((Ax-x)*(Ax-x)+(Ay-y)*(Ay-y));
}
//注:A(Ax,Ay)、B(Bx,By)、C(Cx,Cy)为不在同一条直线上的同一平面上三个点。

你可能感兴趣的:(代码速记)