- Visual C++源码
- Visual Basic源码
- C++ Builder源码
- Java源码
- Delphi源码
- C/C++源码
- PHP源码
- Perl源码
- Python源码
- Asm源码
- Pascal源码
- Borland C++源码
- Others源码
- SQL源码
- VBScript源码
- JavaScript源码
- ASP/ASPX源码
- C#源码
- Flash/ActionScript源码
- matlab源码
- PowerBuilder源码
- LabView源码
- Flex源码
- MathCAD源码
- VBA源码
- IDL源码
- Lisp/Scheme源码
- VHDL源码
- Objective-C源码
- Fortran源码
- tcl/tk源码
- QT源码
Draw1.cpp
资源名称:基本GIS系统开发.rar [点击查看]
上传用户:yklx818
上传日期:2013-04-13
资源大小:459k
文件大小:3k
源码类别:
GIS编程
开发平台:
Visual C++
- // Draw1.cpp: implementation of the CDraw class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "Draw.h"
- #include "Draw1.h"
- #include "math.h"
- #define pi 3.1415926
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- //CDraw::CDraw();
- float GetAngle(float xx,float yy,float m_x,float m_y);
- float GetAngle(float xx,float yy,float m_x,float m_y)
- {
- float i;
- i=(float)acos((m_x-xx)/sqrt((m_y-yy)*(m_y-yy)+(m_x-xx)*(m_x-xx)));
- return i;
- }
- float CDraw::PointLine(float xx,float yy,float x1,float y1,float x2,float y2)
- {
- float a,b,c,ang1,ang2,ang;
- a=CalDisp(x1,y1,xx,yy);
- if(a==0.0)
- return 0.0;
- b=CalDisp(x2,y2,xx,yy);
- if(b==0.0)
- return 0.0;
- c=CalDisp(x1,y1,x2,y2);
- if(c==0.0)
- return a;
- if(a<b)
- {
- if(fabs(y1-y2)<=0.001)
- {
- if(x1<x2)
- ang1=0;
- else
- ang1=(float)pi;
- }
- else
- {
- ang1=(float)acos((x2-x1)/c);
- if(y1>y2)
- ang1=(float)pi*2-ang1;
- }
- ang2=(float)acos((xx-x1)/a);
- if(y1>yy)
- ang2=(float)pi*2-ang2;
- ang=ang2-ang1;
- if(ang<0)
- ang=-ang;
- if(ang>pi)
- ang=(float)pi*2-ang;
- if(ang>pi/2)
- return a;
- else
- return (a*(float)sin(ang));
- }
- else
- {
- if(fabs(y1-y2)<=0.001)
- {
- if(x1<x2)
- ang1=(float)pi;
- else
- ang1=0;
- }
- else
- {
- ang1=(float)acos((x1-x2)/c);
- if(y2>y1)
- ang1=(float)pi*2-ang1;
- }
- ang2=(float)acos((xx-x2)/b);
- if(y2>yy)
- ang2=(float)pi*2-ang2;
- ang=ang2-ang1;
- if(ang<0)
- ang=-ang;
- if(ang>pi)
- ang=(float)pi*2-ang;
- if(ang>pi/2)
- return b;
- else
- return(b*(float)sin(ang));
- }
- }
- float CDraw::CalDisp(float x1,float y1,float x2,float y2)
- {
- return (float)sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
- }
- void CDraw::CalArea()
- {
- }
- void CDraw::CalLong()
- {
- }
- BOOL CDraw::PointRgn(float x,float y,int Numble,PointStruct* PointList,float blc)
- {
- CRgn rgn;
- int x1,y1,i;
- POINT* pPoint;
- if(Numble<3)
- return 0;
- pPoint=new POINT[Numble];
- x1=(int)(x/blc);
- y1=(int)(y/blc);
- for(i=0;i<Numble;i++)
- {
- pPoint[i].x=(int)((PointList[i].x)/blc);
- pPoint[i].y=(int)((PointList[i].y)/blc);
- }
- rgn.CreatePolygonRgn(pPoint,Numble,0);
- i=(rgn.PtInRegion(x1,y1)!=0);
- rgn.DeleteObject();
- return i;
- }
- void CDraw::RotatePoint(float baseX,float baseY,float angle,float *xx,float *yy)
- {
- float xx1,yy1;
- xx1=*xx;
- yy1=*yy;
- double angle1=GetAngle(baseX,baseY,xx1,yy1);
- double j1=CalDisp(baseX,baseY,xx1,yy1);
- xx1=baseX+j1*cos(angle+angle1);
- yy1=baseY+j1*sin(angle+angle1);
- *xx=xx1;
- *yy=yy1;
- }
- float CDraw::GetAngle(float baseX,float baseY,float xx,float yy)
- {
- float r,ang;
- // 如果基点和计算点是同一个点
- if(fabs(baseX-xx)<=0.001&&fabs(baseY-yy)<=0.001)
- return 0;
- if(fabs(baseX-xx)<=0.001)
- {
- if(yy>baseY)
- ang=(float)(pi/2);
- else
- ang=(float)(pi*3/2);
- return ang;
- }
- else
- {
- r=(float)sqrt((xx-baseX)*(xx-baseX)+(yy-baseY)*(yy-baseY));
- double kk=(xx-baseX)/r;
- ang=(float)acos(kk);
- if(yy<baseY)
- ang=(float)(pi*2)-ang;
- return ang;
- }
- }
- void CDraw::Delete(BOOL bDelete)
- {
- b_Delete=bDelete;
- }
- BOOL CDraw::IsFill()
- {
- return FALSE;
- }
- CDraw::~CDraw()
- {
- }