www.pudn.com > triangulation.rar > trianglulationView.cpp, change:2002-06-25,size:67257b
// trianglulationView.cpp : implementation of the CTrianglulationView class
//
#include "stdafx.h"
#include "trianglulation.h"
#include "trianglulationDoc.h"
#include "trianglulationView.h"
#include "math.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define PI 3.14159
#define pointnumer1 1000
#define edgestacknum 150000
#define triangularstacknum 10000
#define edgenum 7000
Tpoint controlpoint[9];
Tpoint viewpoint;
CPoint projectpoint[9];
CPoint mypoint[100];
Edge edgestack[edgestacknum];
Triangular triangular[triangularstacknum];
int RelPoint1=-1,RelPoint2=-1;
int stacknum=0;
int triangularnum=0;
int buttonpointnum=9;
Edge edgeout[edgenum];
CPoint edgepoint[6];
Tpoint canshupoint[25];
CPoint pointxy[25];
int pointnum=9;
//CPoint edgepoint[1000];
/////////////////////////////////////////////////////////////////////////////
// CTrianglulationView
IMPLEMENT_DYNCREATE(CTrianglulationView, CView)
BEGIN_MESSAGE_MAP(CTrianglulationView, CView)
//{{AFX_MSG_MAP(CTrianglulationView)
ON_WM_LBUTTONDOWN()
ON_COMMAND(ID_TRIANGULATE, OnTriangulate)
ON_WM_MOUSEMOVE()
ON_COMMAND(ID_TUXING, OnTuxing)
ON_COMMAND(ID_3d, On3d)
ON_COMMAND(ID_2d, On2d)
ON_COMMAND(ID_developedsurface, Ondevelopedsurface)
ON_COMMAND(ID_SelectPoint, OnSelectPoint)
ON_COMMAND(ID_uvtriangulation, Onuvtriangulation)
ON_COMMAND(ID_ll, Onll)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTrianglulationView construction/destruction
CTrianglulationView::CTrianglulationView()
{
// TODO: add construction code here
controlpoint[0].x =0;
controlpoint[0].y =0;
controlpoint[0].z =0;
controlpoint[1].x =50;
controlpoint[1].y =120;
controlpoint[1].z =100;
controlpoint[2].x =100;
controlpoint[2].y =40;
controlpoint[2].z =50;
controlpoint[3].x =10;
controlpoint[3].y =80;
controlpoint[3].z =150;
controlpoint[4].x =75;
controlpoint[4].y =80;
controlpoint[4].z =200;
controlpoint[5].x =123;
controlpoint[5].y =70;
controlpoint[5].z =-13;
controlpoint[6].x =-15;
controlpoint[6].y =120;
controlpoint[6].z =60;
controlpoint[7].x =80;
controlpoint[7].y =160;
controlpoint[7].z =178;
controlpoint[8].x =130;
controlpoint[8].y =190;
controlpoint[8].z =123;
viewpoint.x =100;
viewpoint.y =200;
viewpoint.z =278;
//the coordinate of the points
mypoint[0].x =200+(0.6+0.2*cos(0*PI/4))*160;
mypoint[0].y =200+(0.5+0.3*sin(0*PI/4))*160;
mypoint[1].x =200+(0.6+0.2*cos(1*PI/4))*160;
mypoint[1].y =200+(0.5+0.3*sin(1*PI/4))*160;
mypoint[2].x =200+(0.6+0.2*cos(2*PI/4))*160;
mypoint[2].y =200+(0.5+0.3*sin(2*PI/4))*160;
mypoint[3].x =200+(0.6+0.2*cos(3*PI/4))*160;
mypoint[3].y =200+(0.5+0.3*sin(3*PI/4))*160;
mypoint[4].x =200+(0.6+0.2*cos(4*PI/4))*160;
mypoint[4].y =200+(0.5+0.3*sin(4*PI/4))*160;
mypoint[5].x =200+(0.6+0.2*cos(5*PI/4))*160;
mypoint[5].y =200+(0.5+0.3*sin(5*PI/4))*160;
mypoint[6].x =200+(0.6+0.2*cos(6*PI/4))*160;
mypoint[6].y =200+(0.5+0.3*sin(6*PI/4))*160;
mypoint[7].x =200+(0.6+0.2*cos(7*PI/4))*160;
mypoint[7].y =200+(0.5+0.3*sin(7*PI/4))*160;
mypoint[8].x =200+(0.6+0.2*cos(8*PI/4))*160;
mypoint[8].y =200+(0.5+0.3*sin(8*PI/4))*160;
edgepoint[0].x =100;
edgepoint[0].y =50;
edgepoint[1].x =250;
edgepoint[1].y =75;
edgepoint[2].x =210;
edgepoint[2].y =200;
edgepoint[3].x =270;
edgepoint[3].y =320;
edgepoint[4].x =190;
edgepoint[4].y =300;
edgepoint[5].x =150;
edgepoint[5].y =175;
for (int i=0;i<edgestacknum;i++)
{
edgestack[i].number1 =-1;
edgestack[i].number2 =-1;
}
for (i=0;i<triangularstacknum;i++)
{
triangular[i].number1 =-1;
triangular[i].number2 =-1;
triangular[i].number3 =-1;
}
edgeout[0].number1=0;
edgeout[0].number2=1;
edgeout[1].number1=1;
edgeout[1].number2=2;
edgeout[2].number1=2;
edgeout[2].number2=3;
edgeout[3].number1=3;
edgeout[3].number2=4;
edgeout[4].number1=4;
edgeout[4].number2=5;
edgeout[5].number1=5;
edgeout[5].number2=0;
edgeout[6].number1=-1;
edgeout[6].number2=-1;
/* mypoint[0].x =221;
mypoint[0].y =146;
mypoint[1].x =(292+222)/2;
mypoint[1].y =(180+146)/2;
mypoint[2].x =292;
mypoint[2].y =180;
mypoint[3].x =(266+327)/2;
mypoint[3].y =(133+156)/2;
mypoint[4].x =228;
mypoint[4].y =173;
mypoint[5].x =200;
mypoint[5].y =160;*/
mypoint[96].x =150;
mypoint[96].y =120;
mypoint[97].x =150;
mypoint[97].y =180;
mypoint[98].x =120;
mypoint[98].y =150;
mypoint[99].x =180;
mypoint[99].y =150;
}
CTrianglulationView::~CTrianglulationView()
{
}
BOOL CTrianglulationView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CTrianglulationView drawing
void CTrianglulationView::OnDraw(CDC* pDC)
{
CTrianglulationDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
/* pDC->MoveTo (edgepoint[0].x ,edgepoint[0].y);
pDC->LineTo (edgepoint[1].x ,edgepoint[1].y);
pDC->LineTo (edgepoint[2].x ,edgepoint[2].y);
pDC->LineTo (edgepoint[3].x ,edgepoint[3].y);
pDC->LineTo (edgepoint[4].x ,edgepoint[4].y);
pDC->LineTo (edgepoint[5].x ,edgepoint[5].y);
pDC->LineTo (edgepoint[0].x ,edgepoint[0].y);*/
// triangulate();
// parametricspace();
// lunkuo();
}
/////////////////////////////////////////////////////////////////////////////
// CTrianglulationView printing
BOOL CTrianglulationView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CTrianglulationView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CTrianglulationView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CTrianglulationView diagnostics
#ifdef _DEBUG
void CTrianglulationView::AssertValid() const
{
CView::AssertValid();
}
void CTrianglulationView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CTrianglulationDoc* CTrianglulationView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTrianglulationDoc)));
return (CTrianglulationDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CTrianglulationView message handlers
void CTrianglulationView::parametricspace()
{
//在三维空间生成表示曲面的形状
CDC *pDC=GetDC();
double u=0.,v=0.;
Tpoint firstpoint;
CPoint nextpoint;
while (v<1.)
{
firstpoint.x =(int)((1-u)*(1-u)*(controlpoint[0].x *(1-v)*(1-v)+2*controlpoint[1].x *v *(1-v)+controlpoint[2].x *v*v)
+2*u*(1-u)*(controlpoint[3].x *(1-v)*(1-v)+2*controlpoint[4].x *v *(1-v)+controlpoint[5].x *v*v)
+u*u*(controlpoint[6].x *(1-v)*(1-v)+2*controlpoint[7].x *v *(1-v)+controlpoint[8].x *v*v));
firstpoint.y =(int)((1-u)*(1-u)*(controlpoint[0].y *(1-v)*(1-v)+2*controlpoint[1].y *v *(1-v)+controlpoint[2].y *v*v)
+2*u*(1-u)*(controlpoint[3].y *(1-v)*(1-v)+2*controlpoint[4].y *v *(1-v)+controlpoint[5].y *v*v)
+u*u*(controlpoint[6].y *(1-v)*(1-v)+2*controlpoint[7].y *v *(1-v)+controlpoint[8].y *v*v));
firstpoint.z =(int)((1-u)*(1-u)*(controlpoint[0].z *(1-v)*(1-v)+2*controlpoint[1].z *v *(1-v)+controlpoint[2].z *v*v)
+2*u*(1-u)*(controlpoint[3].z *(1-v)*(1-v)+2*controlpoint[4].z *v *(1-v)+controlpoint[5].z *v*v)
+u*u*(controlpoint[6].z *(1-v)*(1-v)+2*controlpoint[7].z *v *(1-v)+controlpoint[8].z *v*v));
nextpoint.x =(int)(viewpoint.x +(firstpoint.x -viewpoint.x )*viewpoint.z /(viewpoint.z -firstpoint.z +0.0001))+500;
nextpoint.y =(int)(viewpoint.y +(firstpoint.y -viewpoint.x )*viewpoint.z /(viewpoint.z -firstpoint.z +0.0001));
pDC->MoveTo (nextpoint.x ,nextpoint.y );
while (u<1.0)
{
firstpoint.x =(int)((1-u)*(1-u)*(controlpoint[0].x *(1-v)*(1-v)+2*controlpoint[1].x *v *(1-v)+controlpoint[2].x *v*v)
+2*u*(1-u)*(controlpoint[3].x *(1-v)*(1-v)+2*controlpoint[4].x *v *(1-v)+controlpoint[5].x *v*v)
+u*u*(controlpoint[6].x *(1-v)*(1-v)+2*controlpoint[7].x *v *(1-v)+controlpoint[8].x *v*v));
firstpoint.y =(int)((1-u)*(1-u)*(controlpoint[0].y *(1-v)*(1-v)+2*controlpoint[1].y *v *(1-v)+controlpoint[2].y *v*v)
+2*u*(1-u)*(controlpoint[3].y *(1-v)*(1-v)+2*controlpoint[4].y *v *(1-v)+controlpoint[5].y *v*v)
+u*u*(controlpoint[6].y *(1-v)*(1-v)+2*controlpoint[7].y *v *(1-v)+controlpoint[8].y *v*v));
firstpoint.z =(int)((1-u)*(1-u)*(controlpoint[0].z *(1-v)*(1-v)+2*controlpoint[1].z *v *(1-v)+controlpoint[2].z *v*v)
+2*u*(1-u)*(controlpoint[3].z *(1-v)*(1-v)+2*controlpoint[4].z *v *(1-v)+controlpoint[5].z *v*v)
+u*u*(controlpoint[6].z *(1-v)*(1-v)+2*controlpoint[7].z *v *(1-v)+controlpoint[8].z *v*v));
nextpoint.x =(int)(viewpoint.x +(firstpoint.x -viewpoint.x )*viewpoint.z /(viewpoint.z -firstpoint.z +0.0001))+500;
nextpoint.y =(int)(viewpoint.y +(firstpoint.y -viewpoint.x )*viewpoint.z /(viewpoint.z -firstpoint.z +0.0001));
pDC->LineTo (nextpoint.x ,nextpoint.y );
u=u+0.1;
}
v=v+0.1;
u=0.;
}
u=0.;v=0.;
while (u<1.)
{
firstpoint.x =(int)((1-u)*(1-u)*(controlpoint[0].x *(1-v)*(1-v)+2*controlpoint[1].x *v *(1-v)+controlpoint[2].x *v*v)
+2*u*(1-u)*(controlpoint[3].x *(1-v)*(1-v)+2*controlpoint[4].x *v *(1-v)+controlpoint[5].x *v*v)
+u*u*(controlpoint[6].x *(1-v)*(1-v)+2*controlpoint[7].x *v *(1-v)+controlpoint[8].x *v*v));
firstpoint.y =(int)((1-u)*(1-u)*(controlpoint[0].y *(1-v)*(1-v)+2*controlpoint[1].y *v *(1-v)+controlpoint[2].y *v*v)
+2*u*(1-u)*(controlpoint[3].y *(1-v)*(1-v)+2*controlpoint[4].y *v *(1-v)+controlpoint[5].y *v*v)
+u*u*(controlpoint[6].y *(1-v)*(1-v)+2*controlpoint[7].y *v *(1-v)+controlpoint[8].y *v*v));
firstpoint.z =(int)((1-u)*(1-u)*(controlpoint[0].z *(1-v)*(1-v)+2*controlpoint[1].z *v *(1-v)+controlpoint[2].z *v*v)
+2*u*(1-u)*(controlpoint[3].z *(1-v)*(1-v)+2*controlpoint[4].z *v *(1-v)+controlpoint[5].z *v*v)
+u*u*(controlpoint[6].z *(1-v)*(1-v)+2*controlpoint[7].z *v *(1-v)+controlpoint[8].z *v*v));
nextpoint.x =(int)(viewpoint.x +(firstpoint.x -viewpoint.x )*viewpoint.z /(viewpoint.z -firstpoint.z +0.0001))+500;
nextpoint.y =(int)(viewpoint.y +(firstpoint.y -viewpoint.x )*viewpoint.z /(viewpoint.z -firstpoint.z +0.0001));
pDC->MoveTo (nextpoint.x ,nextpoint.y );
while (v<1.0)
{
firstpoint.x =(int)((1-u)*(1-u)*(controlpoint[0].x *(1-v)*(1-v)+2*controlpoint[1].x *v *(1-v)+controlpoint[2].x *v*v)
+2*u*(1-u)*(controlpoint[3].x *(1-v)*(1-v)+2*controlpoint[4].x *v *(1-v)+controlpoint[5].x *v*v)
+u*u*(controlpoint[6].x *(1-v)*(1-v)+2*controlpoint[7].x *v *(1-v)+controlpoint[8].x *v*v));
firstpoint.y =(int)((1-u)*(1-u)*(controlpoint[0].y *(1-v)*(1-v)+2*controlpoint[1].y *v *(1-v)+controlpoint[2].y *v*v)
+2*u*(1-u)*(controlpoint[3].y *(1-v)*(1-v)+2*controlpoint[4].y *v *(1-v)+controlpoint[5].y *v*v)
+u*u*(controlpoint[6].y *(1-v)*(1-v)+2*controlpoint[7].y *v *(1-v)+controlpoint[8].y *v*v));
firstpoint.z =(int)((1-u)*(1-u)*(controlpoint[0].z *(1-v)*(1-v)+2*controlpoint[1].z *v *(1-v)+controlpoint[2].z *v*v)
+2*u*(1-u)*(controlpoint[3].z *(1-v)*(1-v)+2*controlpoint[4].z *v *(1-v)+controlpoint[5].z *v*v)
+u*u*(controlpoint[6].z *(1-v)*(1-v)+2*controlpoint[7].z *v *(1-v)+controlpoint[8].z *v*v));
nextpoint.x =(int)(viewpoint.x +(firstpoint.x -viewpoint.x )*viewpoint.z /(viewpoint.z -firstpoint.z +0.0001))+500;
nextpoint.y =(int)(viewpoint.y +(firstpoint.y -viewpoint.x )*viewpoint.z /(viewpoint.z -firstpoint.z +0.0001));
pDC->LineTo (nextpoint.x ,nextpoint.y );
v=v+0.1;
}
u=u+0.1;
v=0.;
}
double t=0;
u=0.5+0.2*cos(t);
v=0.5+0.2*sin(t);
firstpoint.x =(int)((1-u)*(1-u)*(controlpoint[0].x *(1-v)*(1-v)+2*controlpoint[1].x *v *(1-v)+controlpoint[2].x *v*v)
+2*u*(1-u)*(controlpoint[3].x *(1-v)*(1-v)+2*controlpoint[4].x *v *(1-v)+controlpoint[5].x *v*v)
+u*u*(controlpoint[6].x *(1-v)*(1-v)+2*controlpoint[7].x *v *(1-v)+controlpoint[8].x *v*v));
firstpoint.y =(int)((1-u)*(1-u)*(controlpoint[0].y *(1-v)*(1-v)+2*controlpoint[1].y *v *(1-v)+controlpoint[2].y *v*v)
+2*u*(1-u)*(controlpoint[3].y *(1-v)*(1-v)+2*controlpoint[4].y *v *(1-v)+controlpoint[5].y *v*v)
+u*u*(controlpoint[6].y *(1-v)*(1-v)+2*controlpoint[7].y *v *(1-v)+controlpoint[8].y *v*v));
firstpoint.z =(int)((1-u)*(1-u)*(controlpoint[0].z *(1-v)*(1-v)+2*controlpoint[1].z *v *(1-v)+controlpoint[2].z *v*v)
+2*u*(1-u)*(controlpoint[3].z *(1-v)*(1-v)+2*controlpoint[4].z *v *(1-v)+controlpoint[5].z *v*v)
+u*u*(controlpoint[6].z *(1-v)*(1-v)+2*controlpoint[7].z *v *(1-v)+controlpoint[8].z *v*v));
nextpoint.x =(int)(viewpoint.x +(firstpoint.x -viewpoint.x )*viewpoint.z /(viewpoint.z -firstpoint.z +0.0001))+500;
nextpoint.y =(int)(viewpoint.y +(firstpoint.y -viewpoint.x )*viewpoint.z /(viewpoint.z -firstpoint.z +0.0001));
pDC->MoveTo (nextpoint.x ,nextpoint.y);
while (t<(2*PI))
{
u=0.6+0.2*cos(t);
v=0.5+0.3*sin(t);
firstpoint.x =(int)((1-u)*(1-u)*(controlpoint[0].x *(1-v)*(1-v)+2*controlpoint[1].x *v *(1-v)+controlpoint[2].x *v*v)
+2*u*(1-u)*(controlpoint[3].x *(1-v)*(1-v)+2*controlpoint[4].x *v *(1-v)+controlpoint[5].x *v*v)
+u*u*(controlpoint[6].x *(1-v)*(1-v)+2*controlpoint[7].x *v *(1-v)+controlpoint[8].x *v*v));
firstpoint.y =(int)((1-u)*(1-u)*(controlpoint[0].y *(1-v)*(1-v)+2*controlpoint[1].y *v *(1-v)+controlpoint[2].y *v*v)
+2*u*(1-u)*(controlpoint[3].y *(1-v)*(1-v)+2*controlpoint[4].y *v *(1-v)+controlpoint[5].y *v*v)
+u*u*(controlpoint[6].y *(1-v)*(1-v)+2*controlpoint[7].y *v *(1-v)+controlpoint[8].y *v*v));
firstpoint.z =(int)((1-u)*(1-u)*(controlpoint[0].z *(1-v)*(1-v)+2*controlpoint[1].z *v *(1-v)+controlpoint[2].z *v*v)
+2*u*(1-u)*(controlpoint[3].z *(1-v)*(1-v)+2*controlpoint[4].z *v *(1-v)+controlpoint[5].z *v*v)
+u*u*(controlpoint[6].z *(1-v)*(1-v)+2*controlpoint[7].z *v *(1-v)+controlpoint[8].z *v*v));
nextpoint.x =(int)(viewpoint.x +(firstpoint.x -viewpoint.x )*viewpoint.z /(viewpoint.z -firstpoint.z +0.0001))+500;
nextpoint.y =(int)(viewpoint.y +(firstpoint.y -viewpoint.x )*viewpoint.z /(viewpoint.z -firstpoint.z +0.0001));
pDC->LineTo (nextpoint.x ,nextpoint.y );
t=t+0.1;
}
}
void CTrianglulationView::triangulate()
{
//the coordinate of the points
CDC *pDC=GetDC();
/* pDC->SetPixel (mypoint[0].x ,mypoint[0].y ,1);
pDC->SetPixel (mypoint[1].x ,mypoint[1].y ,1);
pDC->SetPixel (mypoint[2].x ,mypoint[2].y,1 );
pDC->SetPixel (mypoint[3].x ,mypoint[3].y ,1);
pDC->SetPixel (mypoint[4].x ,mypoint[4].y,1 );
pDC->SetPixel (mypoint[5].x ,mypoint[5].y,1);
pDC->SetPixel (mypoint[6].x ,mypoint[6].y ,1);
pDC->SetPixel (mypoint[7].x ,mypoint[7].y ,1);*/
//init the edge
int i;
double error=1000.;
double d;
int pointnumber=-1;
int stackvary=0;
bool tag1=1,tag2=1;
bool change=1;
int edgenumber=-1;
double d1,d2,d3;
double ar;
int inside=0;
edgestack[0].number1 =0;
edgestack[0].number2 =1;
stacknum++;
while (change)
{
error=1000.0;
pointnumber=-1;
edgenumber=-1;
for (stackvary=0;stackvary<stacknum;stackvary++)
{
for (i=0;i<(pointnum);i++)
{
if ((IsVisual(edgestack[stackvary],i)==1))
{
// d=abs((threepoint(edgestack[stackvary].number1 ,edgestack[stackvary].number2 ,i)-PI/3)*(threepoint(edgestack[stackvary].number1 ,edgestack[stackvary].number2 ,i)-PI/3)
// +(threepoint(edgestack[stackvary].number2 ,edgestack[stackvary].number1 ,i)-PI/3)*(threepoint(edgestack[stackvary].number2 ,edgestack[stackvary].number1 ,i)-PI/3)
// +(threepoint(i,edgestack[stackvary].number1 ,edgestack[stackvary].number2 )-PI/3)*(threepoint(i,edgestack[stackvary].number1 ,edgestack[stackvary].number2 )-PI/3));
/* m=sqrt(3)/2;
d1=abc(AR(edgestack[stackvary].number1 ,edgestack[stackvary].number2 ,i),m);
d2=abc(AR(i,edgestack[stackvary].number1 ,edgestack[stackvary].number2 ),m);
d3=abc(AR(edgestack[stackvary].number2 ,i,edgestack[stackvary].number1 ),m);
d=d1+d2+d3;
d1=(threepoint(edgestack[stackvary].number1 ,edgestack[stackvary].number2 ,i)-PI/3)*(threepoint(edgestack[stackvary].number1 ,edgestack[stackvary].number2 ,i)-PI/3);
d2=(threepoint(edgestack[stackvary].number2 ,edgestack[stackvary].number1 ,i)-PI/3)*(threepoint(edgestack[stackvary].number2 ,edgestack[stackvary].number1 ,i)-PI/3);
d3=(threepoint(i,edgestack[stackvary].number1 ,edgestack[stackvary].number2 )-PI/3)*(threepoint(i,edgestack[stackvary].number1 ,edgestack[stackvary].number2 )-PI/3);
d=d1+d2+d3;*/
// ar=AR(edgestack[stackvary].number1 ,edgestack[stackvary].number2 ,i);
d3=edge(edgestack[stackvary].number1,edgestack[stackvary].number2);
d1=abc(edge(edgestack[stackvary].number2,i),d3);
d2=abc(edge(edgestack[stackvary].number1,i),d3);
d=d1+d2;
// if ((d<error)&&(d1>0.1)&&(d2>0.1)&&(d3>0.1))
if (d<error)
{
error=d;
pointnumber=i;
edgenumber=stackvary;
}
}
}
}
if (pointnumber!=-1)
{
i=0;
inside =PointIsInside(edgestack[edgenumber].number1 ,edgestack[edgenumber].number2 ,pointnumber);
if (inside!=0)
{
pointnumber=inside;
}
while ((tag1==1)&&(i=edgestacknum))
{
if (((pointnumber==edgestack[i].number1 )||(pointnumber==edgestack[i].number2 ))
&&((edgestack[edgenumber].number2 ==edgestack[i].number1 )||(edgestack[edgenumber].number2 ==edgestack[i].number2 )))
tag1=0;
i++;
}
if (tag1==1)
{
edgestack[stacknum].number1 =edgestack[edgenumber].number2 ;
edgestack[stacknum].number2 =pointnumber;
stacknum++;
}
tag1=1;
i=0;
while ((tag2==1)&&(i=edgestacknum))
{
if (((pointnumber==edgestack[i].number1 )||(pointnumber==edgestack[i].number2 ))
&&((edgestack[edgenumber].number1 ==edgestack[i].number1 )||(edgestack[edgenumber].number2 ==edgestack[i].number2 )))
tag2=0;
i++;
}
if (tag2==1)
{
edgestack[stacknum].number1 =edgestack[edgenumber].number1 ;
edgestack[stacknum].number2 =pointnumber;
stacknum++;
}
tag2=1;
triangular[triangularnum].number1 =edgestack[edgenumber].number1;
triangular[triangularnum].number2 =edgestack[edgenumber].number2 ;
triangular[triangularnum].number3 =pointnumber;
triangularnum++;
}
else
change=0;
}
stackvary=0;
while (stackvary<stacknum)
{
pDC->MoveTo (mypoint[edgestack[stackvary].number1 ].x,mypoint[edgestack[stackvary].number1 ].y);
pDC->LineTo (mypoint[edgestack[stackvary].number2 ].x,mypoint[edgestack[stackvary].number2 ].y);
stackvary++;
}
}
bool CTrianglulationView::IsVisual(Edge edge, int number2)
{
//判断点point2对边edge是否可见
double b;
int number1;
bool Intersect1=0;
bool Intersect2=0;
int i;
double length;
bool isout;
if ((number2==edge.number1 )||(number2==edge.number2))
return 0;//点在直线上
/* int d;
d=(int)(fabs((mypoint[edge.number2 ].y -mypoint[edge.number1 ].y )*mypoint[number2].x -(mypoint[edge.number2 ].x -mypoint[edge.number1 ].x )*mypoint[number2].y
+(mypoint[edge.number1 ].y *mypoint[edge.number2 ].x -mypoint[edge.number2 ].y *mypoint[edge.number1 ].x ))
/sqrt((mypoint[edge.number1].y-mypoint[edge.number2].y)*(mypoint[edge.number1].y-mypoint[edge.number2].y)+(mypoint[edge.number1].x-mypoint[edge.number2].x)*(mypoint[edge.number1].x-mypoint[edge.number2].x)));
if (d=5)
return 0;*/
number1=PointRelToEdge(edge);
RelPoint1=-1;
RelPoint2=-1;
isout=Isout(edge.number1 ,edge.number2 ,number2);
if (isout==0)
return 0;
if (number1==-1)
return 0;//没有任何点可见
if (number1==-2)
return 1;//任何点都是可见的
double b1,b2;
b1=(mypoint[edge.number1 ].x -mypoint[edge.number2 ].x)*mypoint[number1].y
+(mypoint[edge.number2 ].y -mypoint[edge.number1 ].y)*mypoint[number1].x
+mypoint[edge.number2].x *mypoint[edge.number1].y -mypoint[edge.number1].x*mypoint[edge.number2].y;
b2=(mypoint[edge.number1 ].x -mypoint[edge.number2 ].x)*mypoint[number2].y
+(mypoint[edge.number2 ].y -mypoint[edge.number1].y)*mypoint[number2].x
+mypoint[edge.number2].x *mypoint[edge.number1].y -mypoint[edge.number1].x*mypoint[edge.number2].y;
b=b1*b2;
if (b<0)
{
i=0;
while ((i<edgestacknum)&&(!Intersect1)&&(!Intersect2))
{
if ((((edgestack[i].number1!=edge.number1 )&&(edgestack[i].number2 !=edge.number2 ))
||((edgestack[i].number2 !=edge.number1 )&&(edgestack[i].number1 !=edge.number2 )))
||(((edgestack[i].number1 !=edge.number1 )&&(edgestack[i].number2 !=number2))
||((edgestack[i].number2 !=edge.number1 )&&(edgestack[i].number1 !=number2))))
Intersect1=IsIntersect(edgestack[i].number1 ,edgestack[i].number2 ,edge.number1 ,number2);
if ((((edgestack[i].number1!=edge.number1 )&&(edgestack[i].number2 !=edge.number2 ))
||((edgestack[i].number2 !=edge.number1 )&&(edgestack[i].number1 !=edge.number2 )))
||(((edgestack[i].number1 !=edge.number2 )&&(edgestack[i].number2 !=number2))
||((edgestack[i].number2 !=edge.number2 )&&(edgestack[i].number1 !=number2))))
Intersect2=IsIntersect(edgestack[i].number1 ,edgestack[i].number2 ,edge.number2 ,number2);
i++;
}
length=(mypoint[edge.number1 ].x -mypoint[edge.number2 ].x )*(mypoint[edge.number1 ].x -mypoint[edge.number2 ].x )+
(mypoint[edge.number1 ].y -mypoint[edge.number2 ].y )*(mypoint[edge.number1 ].y -mypoint[edge.number2 ].y);
double length1,length2;
length1=(mypoint[edge.number1 ].x -mypoint[number2].x )*(mypoint[edge.number1 ].y -mypoint[number2].y )+
(mypoint[edge.number1].y -mypoint[number2].y )*(mypoint[edge.number1 ].y -mypoint[number2].y );
length2=(mypoint[edge.number2 ].x -mypoint[number2].x )*(mypoint[edge.number2 ].y -mypoint[number2].y )+
(mypoint[edge.number2].y -mypoint[number2].y )*(mypoint[edge.number2 ].y -mypoint[number2].y );
/* if ((length1>length2)&&(length1>2*length/3.))
return 0;
if ((length2>length1)&&(length2>2*length/3.))
return 0; */
if ((Intersect1==1)||(Intersect2==1))
return 0;//点不是可见的
else
return 1;
}
else
return 0;//没有任何点可见
}
int CTrianglulationView::PointRelToEdge(Edge edge)
{
int i;
for (i=0;i<triangularstacknum;i++)
{
if ((triangular[i].number1 ==edge.number1 )||(triangular[i].number2 ==edge.number1 )||(triangular [i].number3 ==edge.number1 ))
{
if ((triangular[i].number1 ==edge.number2 )||(triangular[i].number2 ==edge.number2 )||(triangular [i].number3 ==edge.number2 ))
if ((triangular[i].number1 !=edge.number1 )&&(triangular[i].number1 !=edge.number2 ))
{
if (RelPoint1==-1)
RelPoint1=triangular[i].number1 ;
else
RelPoint2=triangular[i].number1 ;
}
else
if ((triangular[i].number2 !=edge.number1 )&&(triangular[i].number2 !=edge.number2 ))
{
if (RelPoint1==-1)
RelPoint1=triangular[i].number2 ;
else
RelPoint2=triangular[i].number2 ;
}
else
{
if (RelPoint1==-1)
RelPoint1=triangular[i].number3 ;
else
RelPoint2=triangular[i].number3 ;
}
}
}
if ((RelPoint1!=-1)&&(RelPoint2!=-1))
{
return -1;//边已经有两个三角形与之相关
}
if ((RelPoint1!=-1)&&(RelPoint2==-1))
{
return RelPoint1;//与之相关的顶点
}
if ((RelPoint2!=-1)&&(RelPoint1==-1))
{
return RelPoint2;//与之相关的顶点
}
if ((RelPoint1==-1)&&(RelPoint2==-1))
{
return -2;//没有顶点与之相关
}
}
double CTrianglulationView::threepoint(int number1, int number2, int number3)
{
//calculate the cos of the three points(number1 is the common point)
double cos;
double l1,l2,m1,m2,n1,n2;
l1=mypoint[number1].y -mypoint[number2].y;
l2=mypoint[number1].y -mypoint[number3].y;
m1=mypoint[number1].x -mypoint[number2].x;
m2=mypoint[number1].x -mypoint[number3].x;
n1=mypoint[number2].x *mypoint[number1].y -mypoint[number1].x *mypoint[number2].y ;
n2=mypoint[number3].x *mypoint[number1].y -mypoint[number1].x *mypoint[number3].y ;
cos =(l1*l2+m1*m2+n1*n2)/(sqrt(l1*l1+m1*m1+n1*n1)*sqrt(l2*l2+m2*m2+n2*n2));
cos=acos(cos);
return cos;
}
bool CTrianglulationView::IsIntersect(int number1, int number2, int number3, int number4)
{
double d1,d2,x,y,f;
if ((number1==number3)||(number1==number4)||(number2==number3)||(number2==number4))
return 0;
if ((number1==-1)||(number2==-1)||(number3==-1)||(number4==-1))
return 0;
d1=((double)mypoint[number4].y -mypoint[number3].y )/(mypoint[number4].x -mypoint[number3].x )-
((double)mypoint[number2].y -mypoint[number1].y )/(mypoint[number2].x -mypoint[number1].x );
d2=((double)mypoint[number2].x *mypoint[number1].y -mypoint[number2].y *mypoint[number1].x )/(mypoint[number2].x -mypoint[number1].x)-
((double)mypoint[number4].x *mypoint[number3].y -mypoint[number3].x *mypoint[number4].y )/(mypoint[number4].x -mypoint[number3].x );
x=(d2/d1);
if (mypoint[number1].x <mypoint[number2].x )
{
if (mypoint[number3].x<mypoint[number4].x)
{
if ((x>=mypoint[number1].x )&&(x=mypoint[number2].x )&&(x>=mypoint[number3].x )&&(x=mypoint[number4].x))
return 1;//不相交
else
return 0;//相交
}
else
{
if (mypoint[number3].x >mypoint[number4].x )
if ((x>=mypoint[number1].x )&&(x=mypoint[number2].x )&&(x>=mypoint[number4].x )&&(x=mypoint[number3].x ))
return 1;//不相交
else
return 0;//相交
}
}
else
{
if (mypoint[number3].x<mypoint[number4].x )
{
if ((x>=mypoint[number2].x )&&(x=mypoint[number1].x )&&(x>=mypoint[number3].x )&&(x=mypoint[number4].x))
return 1;//不相交
else
return 0;//相交
}
else
{
if (mypoint[number3].x >mypoint[number4].x )
if ((x=mypoint[number1].x )&&(x>=mypoint[number2].x )&&(x>=mypoint[number4].x )&&(x=mypoint[number3].x ))
return 1;//不相交
else
return 0;//相交
}
}
}
bool CTrianglulationView::PointToLine(int number1, int number2, int number3)
{
double d1,d2;
d1=sqrt((mypoint[number1].x -mypoint[number2].x )*(mypoint[number1].x -mypoint[number2].x )
-(mypoint[number2].y-mypoint[number1].y )*(mypoint[number2].y -mypoint[number1].y ));
// d2=
return 1;
}
void CTrianglulationView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
mypoint[buttonpointnum].x =point.x ;
mypoint[buttonpointnum].y =point.y ;
CDC *pDC=GetDC();
pDC->SetPixel(mypoint[buttonpointnum].x ,mypoint[buttonpointnum].y ,1);
CString mystr1,mystr2,mystr;
mystr1.Format ("%d",mypoint[buttonpointnum].x );
mystr2.Format ("%d",mypoint[buttonpointnum].y );
mystr=" "+mystr1+","+mystr2;
// pDC->TextOut (mypoint[buttonpointnum].x,mypoint[buttonpointnum].y,mystr);
buttonpointnum++;
// triangulate();
// CView::OnLButtonDown(nFlags, point);
}
void CTrianglulationView::OnTriangulate()
{
// TODO: Add your command handler code here
triangulate();
}
double CTrianglulationView::AR(int number1, int number2, int number3)
{
double d;
d=abs((mypoint[number1].x-mypoint[number2].x )*mypoint[number3].y +(mypoint[number2].y -mypoint[number1].y )*mypoint[number3].x
+(mypoint[number2].x *mypoint[number1].y -mypoint[number2].y *mypoint[number1].x ))/((mypoint[number1].x -mypoint[number2].x )*
(mypoint[number1].x -mypoint[number2].x )+(mypoint[number1].y -mypoint[number2].y )*(mypoint[number1].y -mypoint[number2].y ));
return d;
}
void CTrianglulationView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
/* CDC *pDC=GetDC();
CString mystr1,mystr2,mystr;
mystr1.Format ("%d",point.x);
mystr2.Format ("%d",point.y );
mystr=" "+mystr1+","+mystr2;
pDC->TextOut(point.x ,point.y ,mystr);*/
CView::OnMouseMove(nFlags, point);
}
double CTrianglulationView::abc(double number1, double number2)
{
double m;
m=number1-number2;
if (m>=0.)
return m;
else
{
m=-m;
return m;
}
}
double CTrianglulationView::edge(int number1, int number2)
{
double d;
d=sqrt((mypoint[number1].x -mypoint[number2].x )*(mypoint[number1].x -mypoint[number2].x)
+(mypoint[number1].y -mypoint[number2].y )*(mypoint[number1].y -mypoint[number2].y));
return d;
}
bool CTrianglulationView::IsOutSide(int number1, int number2)
{
// for (i=0;i<edgeout)
return 1;
}
void CTrianglulationView::AboutEdge()
{
/* CPen penblack;
CPen *oldpen;
CDC *pDC=GetDC();
penblack.CreatePen (PS_SOLID,1,1);
oldpen=pDC->SelectObject (&penblack);
pDC->Arc (100,100,400,400,250,100,251,100);
// pDC->Arc (200,200,300,300,250,200,251,200);
pDC->SelectObject (oldpen);*/
double t,t0=0.;
double d=30.;
double r=100.;
double m=150.,n=150.;
double x,y;
CDC *pDC=GetDC();
/* pDC->MoveTo(250,150);
while (t=2*PI)
{
t=t0+acos(1-(d*d)/(r*r));
x=m+r*cos(t);
y=n+r*sin(t);
t0=t;
pDC->LineTo((int)x,(int)y);
}*/
pDC->MoveTo (mypoint[0].x ,mypoint[0].y );
pDC->LineTo (mypoint[1].x ,mypoint[1].y );
pDC->LineTo (mypoint[2].x ,mypoint[2].y );
pDC->LineTo (mypoint[3].x ,mypoint[3].y );
pDC->LineTo (mypoint[4].x ,mypoint[4].y );
pDC->LineTo (mypoint[5].x ,mypoint[5].y );
pDC->LineTo (mypoint[6].x ,mypoint[6].y );
pDC->LineTo (mypoint[7].x ,mypoint[7].y );
pDC->LineTo (mypoint[8].x ,mypoint[8].y );
}
void CTrianglulationView::OnTuxing()
{
// TODO: Add your command handler code here
AboutEdge();
}
int CTrianglulationView::Isout(int number1, int number2,int number3)
{
bool intersect1,intersect2,intersect3,intersect4,intersect5,intersect6,intersect7,intersect8;
intersect1=IsIntersect(0,1,number1,number3);
intersect2=IsIntersect(1,2,number1,number3);
intersect3=IsIntersect(2,3,number1,number3);
intersect4=IsIntersect(3,4,number1,number3);
intersect5=IsIntersect(4,5,number1,number3);
intersect6=IsIntersect(5,6,number1,number3);
intersect7=IsIntersect(6,7,number1,number3);
intersect8=IsIntersect(7,8,number1,number3);
if ((intersect1==0)&&(intersect2==0)&&(intersect3==0)&&(intersect4==0)
&&(intersect5==0)&&(intersect6==0)&&(intersect7==0)&&(intersect8==0))
{
intersect1=IsIntersect(0,1,number1,number3);
intersect2=IsIntersect(1,2,number2,number3);
intersect3=IsIntersect(2,3,number2,number3);
intersect4=IsIntersect(3,4,number2,number3);
intersect5=IsIntersect(4,5,number2,number3);
intersect6=IsIntersect(5,6,number2,number3);
intersect7=IsIntersect(6,7,number2,number3);
intersect8=IsIntersect(7,8,number1,number3);
if ((intersect1==0)&&(intersect2==0)&&(intersect3==0)&&(intersect4==0)
&&(intersect5==0)&&(intersect6==0)&&(intersect7==0)&&(intersect8==0))
return 1;
else
return 0;
}
else
return 0;//is not out
}
void CTrianglulationView::lunkuo()
{
CDC *pDC=GetDC();
double u=0.,v=0.;
Tpoint firstpoint;
CPoint nextpoint;
while ((v=1.))
{
firstpoint.x =(int)((1-u)*(1-u)*(controlpoint[0].x *(1-v)*(1-v)+2*controlpoint[1].x *v *(1-v)+controlpoint[2].x *v*v)
+2*u*(1-u)*(controlpoint[3].x *(1-v)*(1-v)+2*controlpoint[4].x *v *(1-v)+controlpoint[5].x *v*v)
+u*u*(controlpoint[6].x *(1-v)*(1-v)+2*controlpoint[7].x *v *(1-v)+controlpoint[8].x *v*v));
firstpoint.y =(int)((1-u)*(1-u)*(controlpoint[0].y *(1-v)*(1-v)+2*controlpoint[1].y *v *(1-v)+controlpoint[2].y *v*v)
+2*u*(1-u)*(controlpoint[3].y *(1-v)*(1-v)+2*controlpoint[4].y *v *(1-v)+controlpoint[5].y *v*v)
+u*u*(controlpoint[6].y *(1-v)*(1-v)+2*controlpoint[7].y *v *(1-v)+controlpoint[8].y *v*v));
firstpoint.z =(int)((1-u)*(1-u)*(controlpoint[0].z *(1-v)*(1-v)+2*controlpoint[1].z *v *(1-v)+controlpoint[2].z *v*v)
+2*u*(1-u)*(controlpoint[3].z *(1-v)*(1-v)+2*controlpoint[4].z *v *(1-v)+controlpoint[5].z *v*v)
+u*u*(controlpoint[6].z *(1-v)*(1-v)+2*controlpoint[7].z *v *(1-v)+controlpoint[8].z *v*v));
nextpoint.x =(int)(viewpoint.x +(firstpoint.x -viewpoint.x )*viewpoint.z /(viewpoint.z -firstpoint.z +0.0001))+500;
nextpoint.y =(int)(viewpoint.y +(firstpoint.y -viewpoint.x )*viewpoint.z /(viewpoint.z -firstpoint.z +0.0001));
pDC->MoveTo (nextpoint.x ,nextpoint.y );
while (u<1.0)
{
firstpoint.x =(int)((1-u)*(1-u)*(controlpoint[0].x *(1-v)*(1-v)+2*controlpoint[1].x *v *(1-v)+controlpoint[2].x *v*v)
+2*u*(1-u)*(controlpoint[3].x *(1-v)*(1-v)+2*controlpoint[4].x *v *(1-v)+controlpoint[5].x *v*v)
+u*u*(controlpoint[6].x *(1-v)*(1-v)+2*controlpoint[7].x *v *(1-v)+controlpoint[8].x *v*v));
firstpoint.y =(int)((1-u)*(1-u)*(controlpoint[0].y *(1-v)*(1-v)+2*controlpoint[1].y *v *(1-v)+controlpoint[2].y *v*v)
+2*u*(1-u)*(controlpoint[3].y *(1-v)*(1-v)+2*controlpoint[4].y *v *(1-v)+controlpoint[5].y *v*v)
+u*u*(controlpoint[6].y *(1-v)*(1-v)+2*controlpoint[7].y *v *(1-v)+controlpoint[8].y *v*v));
firstpoint.z =(int)((1-u)*(1-u)*(controlpoint[0].z *(1-v)*(1-v)+2*controlpoint[1].z *v *(1-v)+controlpoint[2].z *v*v)
+2*u*(1-u)*(controlpoint[3].z *(1-v)*(1-v)+2*controlpoint[4].z *v *(1-v)+controlpoint[5].z *v*v)
+u*u*(controlpoint[6].z *(1-v)*(1-v)+2*controlpoint[7].z *v *(1-v)+controlpoint[8].z *v*v));
nextpoint.x =(int)(viewpoint.x +(firstpoint.x -viewpoint.x )*viewpoint.z /(viewpoint.z -firstpoint.z +0.0001))+500;
nextpoint.y =(int)(viewpoint.y +(firstpoint.y -viewpoint.x )*viewpoint.z /(viewpoint.z -firstpoint.z +0.0001));
pDC->LineTo (nextpoint.x ,nextpoint.y );
u=u+0.1;
}
v=v+0.99999999;
u=0.;
}
u=0.;v=0.;
while (u=1.)
{
firstpoint.x =(int)((1-u)*(1-u)*(controlpoint[0].x *(1-v)*(1-v)+2*controlpoint[1].x *v *(1-v)+controlpoint[2].x *v*v)
+2*u*(1-u)*(controlpoint[3].x *(1-v)*(1-v)+2*controlpoint[4].x *v *(1-v)+controlpoint[5].x *v*v)
+u*u*(controlpoint[6].x *(1-v)*(1-v)+2*controlpoint[7].x *v *(1-v)+controlpoint[8].x *v*v));
firstpoint.y =(int)((1-u)*(1-u)*(controlpoint[0].y *(1-v)*(1-v)+2*controlpoint[1].y *v *(1-v)+controlpoint[2].y *v*v)
+2*u*(1-u)*(controlpoint[3].y *(1-v)*(1-v)+2*controlpoint[4].y *v *(1-v)+controlpoint[5].y *v*v)
+u*u*(controlpoint[6].y *(1-v)*(1-v)+2*controlpoint[7].y *v *(1-v)+controlpoint[8].y *v*v));
firstpoint.z =(int)((1-u)*(1-u)*(controlpoint[0].z *(1-v)*(1-v)+2*controlpoint[1].z *v *(1-v)+controlpoint[2].z *v*v)
+2*u*(1-u)*(controlpoint[3].z *(1-v)*(1-v)+2*controlpoint[4].z *v *(1-v)+controlpoint[5].z *v*v)
+u*u*(controlpoint[6].z *(1-v)*(1-v)+2*controlpoint[7].z *v *(1-v)+controlpoint[8].z *v*v));
nextpoint.x =(int)(viewpoint.x +(firstpoint.x -viewpoint.x )*viewpoint.z /(viewpoint.z -firstpoint.z +0.0001))+500;
nextpoint.y =(int)(viewpoint.y +(firstpoint.y -viewpoint.x )*viewpoint.z /(viewpoint.z -firstpoint.z +0.0001));
pDC->MoveTo (nextpoint.x ,nextpoint.y );
while (v=1.0)
{
firstpoint.x =(int)((1-u)*(1-u)*(controlpoint[0].x *(1-v)*(1-v)+2*controlpoint[1].x *v *(1-v)+controlpoint[2].x *v*v)
+2*u*(1-u)*(controlpoint[3].x *(1-v)*(1-v)+2*controlpoint[4].x *v *(1-v)+controlpoint[5].x *v*v)
+u*u*(controlpoint[6].x *(1-v)*(1-v)+2*controlpoint[7].x *v *(1-v)+controlpoint[8].x *v*v));
firstpoint.y =(int)((1-u)*(1-u)*(controlpoint[0].y *(1-v)*(1-v)+2*controlpoint[1].y *v *(1-v)+controlpoint[2].y *v*v)
+2*u*(1-u)*(controlpoint[3].y *(1-v)*(1-v)+2*controlpoint[4].y *v *(1-v)+controlpoint[5].y *v*v)
+u*u*(controlpoint[6].y *(1-v)*(1-v)+2*controlpoint[7].y *v *(1-v)+controlpoint[8].y *v*v));
firstpoint.z =(int)((1-u)*(1-u)*(controlpoint[0].z *(1-v)*(1-v)+2*controlpoint[1].z *v *(1-v)+controlpoint[2].z *v*v)
+2*u*(1-u)*(controlpoint[3].z *(1-v)*(1-v)+2*controlpoint[4].z *v *(1-v)+controlpoint[5].z *v*v)
+u*u*(controlpoint[6].z *(1-v)*(1-v)+2*controlpoint[7].z *v *(1-v)+controlpoint[8].z *v*v));
nextpoint.x =(int)(viewpoint.x +(firstpoint.x -viewpoint.x )*viewpoint.z /(viewpoint.z -firstpoint.z +0.0001))+500;
nextpoint.y =(int)(viewpoint.y +(firstpoint.y -viewpoint.x )*viewpoint.z /(viewpoint.z -firstpoint.z +0.0001));
pDC->LineTo (nextpoint.x ,nextpoint.y );
v=v+0.1;
}
u=u+0.999999;
v=0.;
}
double t=0;
u=0.6+0.2*cos(t);
v=0.5+0.2*sin(t);
firstpoint.x =(int)((1-u)*(1-u)*(controlpoint[0].x *(1-v)*(1-v)+2*controlpoint[1].x *v *(1-v)+controlpoint[2].x *v*v)
+2*u*(1-u)*(controlpoint[3].x *(1-v)*(1-v)+2*controlpoint[4].x *v *(1-v)+controlpoint[5].x *v*v)
+u*u*(controlpoint[6].x *(1-v)*(1-v)+2*controlpoint[7].x *v *(1-v)+controlpoint[8].x *v*v));
firstpoint.y =(int)((1-u)*(1-u)*(controlpoint[0].y *(1-v)*(1-v)+2*controlpoint[1].y *v *(1-v)+controlpoint[2].y *v*v)
+2*u*(1-u)*(controlpoint[3].y *(1-v)*(1-v)+2*controlpoint[4].y *v *(1-v)+controlpoint[5].y *v*v)
+u*u*(controlpoint[6].y *(1-v)*(1-v)+2*controlpoint[7].y *v *(1-v)+controlpoint[8].y *v*v));
firstpoint.z =(int)((1-u)*(1-u)*(controlpoint[0].z *(1-v)*(1-v)+2*controlpoint[1].z *v *(1-v)+controlpoint[2].z *v*v)
+2*u*(1-u)*(controlpoint[3].z *(1-v)*(1-v)+2*controlpoint[4].z *v *(1-v)+controlpoint[5].z *v*v)
+u*u*(controlpoint[6].z *(1-v)*(1-v)+2*controlpoint[7].z *v *(1-v)+controlpoint[8].z *v*v));
nextpoint.x =(int)(viewpoint.x +(firstpoint.x -viewpoint.x )*viewpoint.z /(viewpoint.z -firstpoint.z +0.0001))+500;
nextpoint.y =(int)(viewpoint.y +(firstpoint.y -viewpoint.x )*viewpoint.z /(viewpoint.z -firstpoint.z +0.0001));
pDC->MoveTo (nextpoint.x ,nextpoint.y);
while (t=(2*PI))
{
u=0.6+0.2*cos(t);
v=0.5+0.3*sin(t);
firstpoint.x =(int)((1-u)*(1-u)*(controlpoint[0].x *(1-v)*(1-v)+2*controlpoint[1].x *v *(1-v)+controlpoint[2].x *v*v)
+2*u*(1-u)*(controlpoint[3].x *(1-v)*(1-v)+2*controlpoint[4].x *v *(1-v)+controlpoint[5].x *v*v)
+u*u*(controlpoint[6].x *(1-v)*(1-v)+2*controlpoint[7].x *v *(1-v)+controlpoint[8].x *v*v));
firstpoint.y =(int)((1-u)*(1-u)*(controlpoint[0].y *(1-v)*(1-v)+2*controlpoint[1].y *v *(1-v)+controlpoint[2].y *v*v)
+2*u*(1-u)*(controlpoint[3].y *(1-v)*(1-v)+2*controlpoint[4].y *v *(1-v)+controlpoint[5].y *v*v)
+u*u*(controlpoint[6].y *(1-v)*(1-v)+2*controlpoint[7].y *v *(1-v)+controlpoint[8].y *v*v));
firstpoint.z =(int)((1-u)*(1-u)*(controlpoint[0].z *(1-v)*(1-v)+2*controlpoint[1].z *v *(1-v)+controlpoint[2].z *v*v)
+2*u*(1-u)*(controlpoint[3].z *(1-v)*(1-v)+2*controlpoint[4].z *v *(1-v)+controlpoint[5].z *v*v)
+u*u*(controlpoint[6].z *(1-v)*(1-v)+2*controlpoint[7].z *v *(1-v)+controlpoint[8].z *v*v));
nextpoint.x =(int)(viewpoint.x +(firstpoint.x -viewpoint.x )*viewpoint.z /(viewpoint.z -firstpoint.z +0.0001))+500;
nextpoint.y =(int)(viewpoint.y +(firstpoint.y -viewpoint.x )*viewpoint.z /(viewpoint.z -firstpoint.z +0.0001));
pDC->LineTo (nextpoint.x ,nextpoint.y );
t=t+0.1;
}
}
void CTrianglulationView::uvpingmian()
{
CDC *pDC=GetDC();
double u,v;
double t=0.;
pDC->MoveTo (200+0.8*100,0.5*100+200);
while (t<(2*PI))
{
u=200+(0.6+0.2*cos(t))*100;
v=200+(0.5+0.3*sin(t))*100;
pDC->LineTo (u,v);
t=t+0.1;
}
pDC->MoveTo (200,200);
pDC->LineTo (300,200);
pDC->LineTo (300,300);
pDC->LineTo (200,300);
pDC->LineTo (200,200);
}
void CTrianglulationView::On3d()
{
// TODO: Add your command handler code here
// Invalidate();
// lunkuo();
parametricspace();
}
void CTrianglulationView::On2d()
{
// TODO: Add your command handler code here
// Invalidate();
uvpingmian();
}
void CTrianglulationView::Ondevelopedsurface()
{
// TODO: Add your command handler code here
/* CPoint linshipoint[9];
linshipoint[0].x =400;
linshipoint[0].y =200;
double d;
d=length(controlpoint[2],controlpoint[5]);
linshipoint[1].x =(int)(linshipoint[0].x +d);
linshipoint[1].y =linshipoint[0].y ;
double jiaodu;
jiaodu =jiajiao(controlpoint[2],controlpoint[1],controlpoint[5]);
d =length(controlpoint[2],controlpoint[1]);
linshipoint[2].x =(int)(linshipoint[0].x +d*cos(jiaodu));
linshipoint[2].y =(int)(linshipoint[0].y +d*sin(jiaodu));
CDC *pDC=GetDC();
pDC->MoveTo(linshipoint[0].x ,linshipoint[0].y);
pDC->LineTo (linshipoint[1].x ,linshipoint[1].y );
pDC->MoveTo (linshipoint[0].x ,linshipoint[0].y );
pDC->LineTo (linshipoint[2].x ,linshipoint[2].y );
double m,n;
double p,q;
double r1,r2,r3;
int x,y;
int x1,y1,x2,y2;
double a,b;
r1=length(controlpoint[1],controlpoint[4]);
r2=length(controlpoint[5],controlpoint[4]);
r3=length(controlpoint[2],controlpoint[4]);
m=linshipoint[2].x ;
n=linshipoint[2].y ;
p=linshipoint[1].x ;
q=linshipoint[1].y ;
a=((double)r1*r1-r2*r2+q*q-n*n)/(2*((double)p-m))+(p-(double)m)/2.;
b=((double)q-n)/((double)p-m);
y1=(int)((a*b+n+sqrt((a*b+n)*(a*b+n)-(b*b+1)*(a*a+n*n-r1*r1)))/(b*b+1));
x1=(int)(a+m-b*y1);
y2=(int)((a*b+n-sqrt((a*b+n)*(a*b+n)-(b*b+1)*(a*a+n*n-r1*r1)))/(b*b+1));
x2=(int)(a+m-b*y2);
Edge myedge[20];
for (int i=0;i<20;i++)
{
myedge[i].number1 =-1;
myedge[i].number2 =-1;
}
myedge[0].number1 =0;
myedge[0].number2 =1;
myedge[1].number1 =0;
myedge[1].number2 =2;
bool intersect=0;
i=0;
while ((i<9)&&!intersect)
{
intersect=Intersect(linshipoint[myedge[i].number1 ].x,linshipoint[myedge[i].number1 ].y ,linshipoint[myedge[i].number2 ].x ,
linshipoint[myedge[i].number2 ].y ,)
}
double error1,error2;
double d1,d2;
d1=sqrt((x1-linshipoint[0].x )*(x1-linshipoint[0].x )+(y1-linshipoint[0].y)*(y1-linshipoint[0].y ));
d2=sqrt((x2-linshipoint[0].x )*(x2-linshipoint[0].x )+(y2-linshipoint[0].y)*(y2-linshipoint[0].y ));
error1=abc(d1,0);
error2=abc(d2,0);
if (error1=error2)
{
x=x1;
y=y1;
}
else
{
x=x2;
y=y2;
}
pDC->MoveTo (linshipoint[1].x ,linshipoint[1].y );
pDC->LineTo (x1,y1);
pDC->LineTo (linshipoint[2].x ,linshipoint[2].y );
linshipoint[3].x =x1;
linshipoint[3].y =y1;
jiaodu =jiajiao(controlpoint[5],controlpoint[4],controlpoint[8]);
d =length(controlpoint[5],controlpoint[8]);
linshipoint[4].x =(int)(linshipoint[1].x +d*sin(jiaodu));
linshipoint[4].y =(int)(linshipoint[1].y +d*cos(jiaodu));
pDC->MoveTo (linshipoint[1].x ,linshipoint[1].y );
pDC->LineTo (linshipoint[4].x ,linshipoint[4].y );
jiaodu =jiajiao(controlpoint[1],controlpoint[0],controlpoint[4]);
d =length(controlpoint[0],controlpoint[1]);
linshipoint[5].x =(int)(linshipoint[2].x +d*cos(jiaodu));
linshipoint[5].y =(int)(linshipoint[2].y +d*sin(jiaodu));
pDC->MoveTo (linshipoint[2].x ,linshipoint[2].y );
pDC->LineTo (linshipoint[5].x ,linshipoint[5].y );
r1=length(controlpoint[7],controlpoint[4]);
r2=length(controlpoint[7],controlpoint[8]);
r3=length(controlpoint[7],controlpoint[5]);
m=linshipoint[3].x ;
n=linshipoint[3].y ;
p=linshipoint[4].x ;
q=linshipoint[4].y ;
a=((double)r1*r1-r2*r2+q*q-n*n)/(2*((double)p-m))+(p-(double)m)/2.;
b=((double)q-n)/((double)p-m);
y1=(int)((a*b+n+sqrt((a*b+n)*(a*b+n)-(b*b+1)*(a*a+n*n-r1*r1)))/(b*b+1));
x1=(int)(a+m-b*y1);
y2=(int)((a*b+n-sqrt((a*b+n)*(a*b+n)-(b*b+1)*(a*a+n*n-r1*r1)))/(b*b+1));
x2=(int)(a+m-b*y2);
d1=sqrt((x1-linshipoint[1].x )*(x1-linshipoint[1].x )+(y1-linshipoint[1].y)*(y1-linshipoint[1].y ));
d2=sqrt((x2-linshipoint[1].x )*(x2-linshipoint[1].x )+(y2-linshipoint[1].y)*(y2-linshipoint[1].y ));
error1=abc(d1,0);
error2=abc(d2,0);
if (error1=error2)
{
x=x1;
y=y1;
}
else
{
x=x2;
y=y2;
}
linshipoint[6].x =400;
linshipoint[6].y =625;
pDC->MoveTo (linshipoint[4].x ,linshipoint[4].y );
pDC->LineTo (500,425);
pDC->LineTo (linshipoint[3].x ,linshipoint[3].y );
r1=length(controlpoint[0],controlpoint[3]);
r2=length(controlpoint[4],controlpoint[3]);
r3=length(controlpoint[1],controlpoint[3]);
m=linshipoint[5].x ;
n=linshipoint[5].y ;
p=linshipoint[3].x ;
q=linshipoint[3].y ;
a=((double)r1*r1-r2*r2+q*q-n*n)/(2*((double)p-m))+(p-(double)m)/2.;
b=((double)q-n)/((double)p-m);
y1=(int)((a*b+n+sqrt((a*b+n)*(a*b+n)-(b*b+1)*(a*a+n*n-r1*r1)))/(b*b+1));
x1=(int)(a+m-b*y1);
y2=(int)((a*b+n-sqrt((a*b+n)*(a*b+n)-(b*b+1)*(a*a+n*n-r1*r1)))/(b*b+1));
x2=(int)(a+m-b*y2);
d1=sqrt((x1-linshipoint[2].x )*(x1-linshipoint[2].x )+(y1-linshipoint[2].y)*(y1-linshipoint[2].y ));
d2=sqrt((x2-linshipoint[2].x )*(x2-linshipoint[2].x )+(y2-linshipoint[2].y)*(y2-linshipoint[2].y ));
error1=abc(d1,0);
error2=abc(d2,0);
if (error1=error2)
{
x=x1;
y=y1;
}
else
{
x=x2;
y=y2;
}
linshipoint[7].x =x;
linshipoint[7].y =y;
pDC->MoveTo (linshipoint[5].x ,linshipoint[5].y );
pDC->LineTo (376,512);
pDC->LineTo (linshipoint[3].x ,linshipoint[3].y );
r1=length(controlpoint[3],controlpoint[6]);
r2=length(controlpoint[7],controlpoint[6]);
r3=length(controlpoint[4],controlpoint[6]);
m=linshipoint[7].x ;
n=linshipoint[7].y ;
p=linshipoint[6].x ;
q=linshipoint[6].y ;
a=(r1*r1-r2*r2+q*q-n*n)/(2*(p-m))+(p-m)/2;
b=(q-n)/(p-m);
y1=(int)((a*b+n+sqrt((a*b+n)*(a*b+n)-(b*b+1)*(a*a+n*n-r1*r1)))/(b*b+1));
x1=(int)(a+m-b*y1);
y2=(int)((a*b+n-sqrt((a*b+n)*(a*b+n)-(b*b+1)*(a*a+n*n-r1*r1)))/(b*b+1));
x2=(int)(a+m-b*y2);
d1=sqrt((x1-linshipoint[3].x )*(x1-linshipoint[3].x )+(y1-linshipoint[3].y)*(y1-linshipoint[3].y ));
d2=sqrt((x2-linshipoint[3].x )*(x2-linshipoint[3].x )+(y2-linshipoint[3].y)*(y2-linshipoint[3].y ));
error1=abc(d1,0);
error2=abc(d2,0);
if (error1=error2)
{
x=x1;
y=y1;
}
else
{
x=x2;
y=y2;
}
linshipoint[8].x =x;
linshipoint[8].y =y;
pDC->MoveTo (linshipoint[1].x ,linshipoint[1].y );
pDC->LineTo (linshipoint[4].x ,linshipoint[4].y );
pDC->LineTo (linshipoint[6].x ,linshipoint[6].y );
pDC->LineTo (linshipoint[3].x ,linshipoint[3].y );
pDC->LineTo (linshipoint[7].x ,linshipoint[7].y );
pDC->LineTo (linshipoint[5].x ,linshipoint[5].y );
pDC->LineTo (linshipoint[2].x ,linshipoint[2].y );
pDC->MoveTo (linshipoint[7].x ,linshipoint[7].y );
pDC->LineTo (linshipoint[8].x ,linshipoint[8].y );
pDC->LineTo (linshipoint[6].x ,linshipoint[6].y );*/
CPoint pointx[25];
CPoint pointy[25];
double d;
canshufuzhi();
pointx[0].x =300;
pointx[0].y =300;
d=length(canshupoint[0],canshupoint[5]);
pointx[5].x =(int)(pointx[0].x +d);
pointx[5].y =pointx[0].y ;
d=length(canshupoint[5],canshupoint[10]);
pointx[10].x =(int)(pointx[5].x +d);
pointx[10].y =pointx[0].y ;
d=length(canshupoint[10],canshupoint[15]);
pointx[15].x =(int)(pointx[10].x +d);
pointx[15].y =pointx[0].y ;
d=length(canshupoint[15],canshupoint[20]);
pointx[20].x =(int)(pointx[15].x +d);
pointx[20].y =pointx[0].y ;
double cs;
cs=jiajiao(canshupoint[0],canshupoint[1],canshupoint[5]);
d=length(canshupoint[0],canshupoint[1]);
pointx[1].x =(int)(d*cos(cs)+pointx[0].x );
pointx[1].y =(int)(d*sin(cs)+pointx[0].y );
d=length(canshupoint[1],canshupoint[6]);
pointx[6].x =(int)(pointx[1].x +d);
pointx[6].y =pointx[1].y ;
d=length(canshupoint[6],canshupoint[11]);
pointx[11].x =(int)(pointx[6].x +d);
pointx[11].y =pointx[6].y ;
d=length(canshupoint[11],canshupoint[16]);
pointx[16].x =(int)(pointx[11].x +d);
pointx[16].y =pointx[1].y ;
d=length(canshupoint[16],canshupoint[21]);
pointx[21].x =(int)(pointx[16].x +d);
pointx[21].y =pointx[1].y ;
cs=jiajiao(canshupoint[1],canshupoint[2],canshupoint[6]);
d=length(canshupoint[2],canshupoint[1]);
pointx[2].x =(int)(d*cos(cs)+pointx[1].x );
pointx[2].y =(int)(d*sin(cs)+pointx[1].y );
d=length(canshupoint[2],canshupoint[7]);
pointx[7].x =(int)(pointx[2].x +d);
pointx[7].y =pointx[2].y ;
d=length(canshupoint[7],canshupoint[12]);
pointx[12].x =(int)(pointx[7].x +d);
pointx[12].y =pointx[2].y ;
d=length(canshupoint[12],canshupoint[17]);
pointx[17].x =(int)(pointx[12].x +d);
pointx[17].y =pointx[2].y ;
d=length(canshupoint[17],canshupoint[22]);
pointx[22].x =(int)(pointx[17].x +d);
pointx[22].y =pointx[2].y ;
cs=jiajiao(canshupoint[2],canshupoint[3],canshupoint[7]);
d=length(canshupoint[2],canshupoint[3]);
pointx[3].x =(int)(d*cos(cs)+pointx[2].x );
pointx[3].y =(int)(d*sin(cs)+pointx[2].y );
d=length(canshupoint[3],canshupoint[8]);
pointx[8].x =(int)(pointx[3].x +d);
pointx[8].y =pointx[3].y ;
d=length(canshupoint[8],canshupoint[13]);
pointx[13].x =(int)(pointx[8].x +d);
pointx[13].y =pointx[3].y ;
d=length(canshupoint[13],canshupoint[18]);
pointx[18].x =(int)(pointx[13].x +d);
pointx[18].y =pointx[3].y ;
d=length(canshupoint[18],canshupoint[23]);
pointx[23].x =(int)(pointx[18].x +d);
pointx[23].y =pointx[3].y ;
cs=jiajiao(canshupoint[3],canshupoint[4],canshupoint[8]);
d=length(canshupoint[3],canshupoint[4]);
pointx[4].x =(int)(d*cos(cs)+pointx[3].x );
pointx[4].y =(int)(d*sin(cs)+pointx[3].y );
d=length(canshupoint[4],canshupoint[9]);
pointx[9].x =(int)(pointx[4].x +d);
pointx[9].y =pointx[4].y ;
d=length(canshupoint[9],canshupoint[14]);
pointx[14].x =(int)(pointx[9].x +d);
pointx[14].y =pointx[4].y ;
d=length(canshupoint[14],canshupoint[19]);
pointx[19].x =(int)(pointx[14].x +d);
pointx[19].y =pointx[4].y ;
d=length(canshupoint[19],canshupoint[24]);
pointx[24].x =(int)(pointx[19].x +d);
pointx[24].y =pointx[4].y ;
pointy[0].x =300;
pointy[0].y =300;
d=length(canshupoint[0],canshupoint[1]);
pointy[1].y =(int)(pointy[0].y +d);
pointy[1].x =pointy[0].x ;
d=length(canshupoint[1],canshupoint[2]);
pointy[2].y =(int)(pointy[1].y +d);
pointy[2].x =pointy[0].x ;
d=length(canshupoint[1],canshupoint[2]);
pointy[3].y =(int)(pointy[2].y +d);
pointy[3].x =pointy[0].x ;
d=length(canshupoint[1],canshupoint[2]);
pointy[4].y =(int)(pointy[3].y +d);
pointy[4].x =pointy[0].x ;
// double cs;
cs=jiajiao(canshupoint[0],canshupoint[1],canshupoint[5]);
d=length(canshupoint[0],canshupoint[5]);
pointy[5].x =(int)(d*sin(cs)+pointy[0].x );
pointy[5].y =(int)(d*cos(cs)+pointy[0].y );
d=length(canshupoint[5],canshupoint[6]);
pointy[6].y =(int)(pointy[5].y +d);
pointy[6].x =pointy[5].x ;
d=length(canshupoint[6],canshupoint[7]);
pointy[7].y=(int)(pointy[6].y +d);
pointy[7].x =pointy[5].x ;
d=length(canshupoint[7],canshupoint[8]);
pointy[8].y=(int)(pointy[7].y +d);
pointy[8].x =pointy[5].x ;
d=length(canshupoint[8],canshupoint[9]);
pointy[9].y=(int)(pointy[8].y +d);
pointy[9].x =pointy[5].x ;
cs=jiajiao(canshupoint[5],canshupoint[6],canshupoint[10]);
d=length(canshupoint[5],canshupoint[10]);
pointy[10].x =(int)(d*sin(cs)+pointy[5].x );
pointy[10].y =(int)(d*cos(cs)+pointy[5].y );
d=length(canshupoint[10],canshupoint[11]);
pointy[11].y =(int)(pointy[10].x +d);
pointy[11].x =pointy[10].x ;
d=length(canshupoint[11],canshupoint[12]);
pointy[12].y =(int)(pointy[11].y +d);
pointy[12].x =pointy[10].x ;
d=length(canshupoint[12],canshupoint[13]);
pointy[13].y =(int)(pointy[12].y +d);
pointy[13].x =pointy[10].x ;
d=length(canshupoint[13],canshupoint[14]);
pointy[14].y =(int)(pointy[13].y +d);
pointy[14].x =pointy[10].x ;
cs=jiajiao(canshupoint[3],canshupoint[6],canshupoint[4]);
d=length(canshupoint[3],canshupoint[6]);
pointy[6].x =(int)(d*sin(cs)+pointy[3].x );
pointy[6].y =(int)(d*cos(cs)+pointy[3].y );
d=length(canshupoint[6],canshupoint[7]);
pointy[7].y =(int)(pointy[6].x +d);
pointy[7].x =pointy[6].x ;
d=length(canshupoint[7],canshupoint[8]);
pointy[8].y =(int)(pointy[7].y +d);
pointy[8].x =pointy[6].x ;
d=length(canshupoint[7],canshupoint[8]);
pointy[8].y =(int)(pointy[7].y +d);
pointy[8].x =pointy[6].x ;
d=length(canshupoint[7],canshupoint[8]);
pointy[8].y =(int)(pointy[7].y +d);
pointy[8].x =pointy[6].x ;
cs=jiajiao(canshupoint[3],canshupoint[6],canshupoint[4]);
d=length(canshupoint[3],canshupoint[6]);
pointy[6].x =(int)(d*sin(cs)+pointy[3].x );
pointy[6].y =(int)(d*cos(cs)+pointy[3].y );
d=length(canshupoint[6],canshupoint[7]);
pointy[7].y =(int)(pointy[6].x +d);
pointy[7].x =pointy[6].x ;
d=length(canshupoint[7],canshupoint[8]);
pointy[8].y =(int)(pointy[7].y +d);
pointy[8].x =pointy[6].x ;
d=length(canshupoint[7],canshupoint[8]);
pointy[8].y =(int)(pointy[7].y +d);
pointy[8].x =pointy[6].x ;
d=length(canshupoint[7],canshupoint[8]);
pointy[8].y =(int)(pointy[7].y +d);
pointy[8].x =pointy[6].x ;
int i=0;
for (i=0;i<9;i++)
{
pointxy[i].x =(int)((pointx[i].x +pointy[i].x )/2.);
pointxy[i].y =(int)((pointx[i].y +pointy[i].y )/2.);
}
CDC *pDC=GetDC();
pDC->MoveTo (pointxy[0].x ,pointxy[0].y );
pDC->LineTo (pointxy[1].x,pointxy[1].y );
pDC->LineTo (pointxy[2].x,pointxy[2].y );
pDC->LineTo (pointxy[5].x,pointxy[5].y );
pDC->LineTo (pointxy[8].x,pointxy[8].y );
pDC->LineTo (pointxy[7].x,pointxy[7].y );
pDC->LineTo (pointxy[6].x,pointxy[6].y );
pDC->LineTo (pointxy[3].x,pointxy[3].y );
pDC->LineTo (pointxy[0].x,pointxy[0].y );
pDC->MoveTo (pointxy[1].x ,pointxy[1].y );
pDC->LineTo (pointxy[4].x,pointxy[4].y );
pDC->LineTo (pointxy[7].x,pointxy[7].y );
pDC->MoveTo (pointxy[3].x ,pointxy[3].y );
pDC->LineTo (pointxy[4].x,pointxy[4].y );
pDC->LineTo (pointxy[5].x,pointxy[5].y );
double t=0;
double u,v;
/* while (t=2*PI)
{
u=0.6+0.2*cos(t);
v=0.5+0.3*sin(t);
developpoint(u,v);
t=t+0.05;
}*/
}
double CTrianglulationView::jiajiao(Tpoint point1, Tpoint point2,Tpoint point3)
{
double ax,ay,az,bx,by,bz;
ax=point2.x -point1.x;
ay=point2.y -point1.y;
az=point2.z -point1.z;
bx=point3.x -point1.x ;
by=point3.y -point1.y ;
bz=point3.z -point1.z ;
double cos;
double m,n;
m=sqrt(ax*ax+ay*ay+az*az);
n=sqrt(bx*bx+by*by+bz*bz);
cos =(ax*bx+ay*by+az*bz)/(m*n);
return acos(cos);
}
double CTrianglulationView::length(Tpoint point1, Tpoint point2)
{
double d;
d=sqrt((point1.x -point2.x )*(point1.x -point2.x )+(point1.y -point2.y )*(point1.y -point2.y )+(point1.z -point2.z )*(point1.z -point2.z ));
return d;
}
bool CTrianglulationView::Intersect(int point1x,int point1y,int point2x, int point2y, int point3x,int point3y, int point4x,int point4y)
{
double d1,d2,x,y,f;
d1=((double)point4y -point3y )/(point4x -point3x )-
((double)point2y -point1y )/(point2x -point2x );
d2=((double)point2x *point1y -point2y *point1x)/(point2x -point1x)-
((double)point4x *point3y -point3x *point4y )/(point4x -point3x);
x=(d2/d1);
if (point1x <point2x )
{
if (point3x<point4x)
{
if ((x>point1x )&&(x<point2x )&&(x>point3x )&&(x<point4x))
return 1;//相交
else
return 0;//不相交
}
else
{
if (point3x >point4x )
if ((x>point1x )&&(x<point2x )&&(x>point4x )&&(x<point3x ))
return 1;//相交
else
return 0;//不相交
}
}
else
{
if (point3x<point4x )
{
if ((x>point2x )&&(x<point1x )&&(x>point3x )&&(x<point4x))
return 1;//不相交
else
return 0;//相交
}
else
{
if (point3x >point4x )
if ((x<point1x )&&(x>point2x )&&(x>point4x )&&(x<point3x ))
return 1;//不相交
else
return 0;//相交
}
}
}
void CTrianglulationView::canshufuzhi()
{
/* canshupoint[0].x =(int)fuzhix(0.,0.);
canshupoint[0].y =(int)fuzhiy(0.,0.);
canshupoint[0].z =(int)fuzhiz(0.,0.);
canshupoint[1].x =(int)fuzhix(0.,0.5);
canshupoint[1].y =(int)fuzhiy(0.,0.5);
canshupoint[1].z =(int)fuzhiz(0.,0.5);
canshupoint[2].x =(int)fuzhix(0.,1.);
canshupoint[2].y =(int)fuzhiy(0.,1.);
canshupoint[2].z =(int)fuzhiz(0.,1.);
canshupoint[3].x =(int)fuzhix(0.5,0.);
canshupoint[3].y =(int)fuzhiy(0.5,0.);
canshupoint[3].z =(int)fuzhiz(0.5,0.);
canshupoint[4].x =(int)fuzhix(0.5,0.5);
canshupoint[4].y =(int)fuzhiy(0.5,0.5);
canshupoint[4].z =(int)fuzhiz(0.5,0.5);
canshupoint[5].x =(int)fuzhix(0.5,1.);
canshupoint[5].y =(int)fuzhiy(0.5,1.);
canshupoint[5].z =(int)fuzhiz(0.5,1.);
canshupoint[6].x =(int)fuzhix(1.,0.);
canshupoint[6].y =(int)fuzhiy(1.,0.);
canshupoint[6].z =(int)fuzhiz(1.,0.);
canshupoint[7].x =(int)fuzhix(1.,0.5);
canshupoint[7].y =(int)fuzhiy(1.,0.5);
canshupoint[7].z =(int)fuzhiz(1.,0.5);
canshupoint[8].x =(int)fuzhix(1.,1.);
canshupoint[8].y =(int)fuzhiy(1.,1.);
canshupoint[8].z =(int)fuzhiz(1.,1.);*/
double u,v;
u=0.;
v=0.;
int number=0;
while (u=1.)
{
while (v=1.)
{
canshupoint[number].x =(int)fuzhix(u,v);
canshupoint[number].y =(int)fuzhiy(u,v);
canshupoint[number].z =(int)fuzhiz(u,v);
v=v+0.25;
number++;
}
u=u+0.25;
v=0.;
}
}
double CTrianglulationView::fuzhix(double u, double v)
{
double d;
d =(int)((1-u)*(1-u)*(controlpoint[0].x *(1-v)*(1-v)+2*controlpoint[1].x *v *(1-v)+controlpoint[2].x *v*v)
+2*u*(1-u)*(controlpoint[3].x *(1-v)*(1-v)+2*controlpoint[4].x *v *(1-v)+controlpoint[5].x *v*v)
+u*u*(controlpoint[6].x *(1-v)*(1-v)+2*controlpoint[7].x *v *(1-v)+controlpoint[8].x *v*v));
return d;
}
double CTrianglulationView::fuzhiy(double u, double v)
{
double d;
d =(int)((1-u)*(1-u)*(controlpoint[0].y *(1-v)*(1-v)+2*controlpoint[1].y *v *(1-v)+controlpoint[2].y *v*v)
+2*u*(1-u)*(controlpoint[3].y *(1-v)*(1-v)+2*controlpoint[4].y *v *(1-v)+controlpoint[5].y *v*v)
+u*u*(controlpoint[6].y *(1-v)*(1-v)+2*controlpoint[7].y *v *(1-v)+controlpoint[8].y *v*v));
return d;
}
double CTrianglulationView::fuzhiz(double u, double v)
{
double d;
d =(int)((1-u)*(1-u)*(controlpoint[0].z *(1-v)*(1-v)+2*controlpoint[1].z *v *(1-v)+controlpoint[2].z *v*v)
+2*u*(1-u)*(controlpoint[3].z *(1-v)*(1-v)+2*controlpoint[4].z *v *(1-v)+controlpoint[5].z *v*v)
+u*u*(controlpoint[6].z *(1-v)*(1-v)+2*controlpoint[7].z *v *(1-v)+controlpoint[8].z *v*v));
return d;
}
void CTrianglulationView::developpoint(double u, double v)
{
CDC *pDC=GetDC();
int tag;
if ((u=0.5)&&(v=0.5))
tag=1;
if ((u=0.5)&&(v>0.5))
tag=2;
if ((u>0.5)&&(v=0.5))
tag=3;
if ((u>0.5)&&(v>0.5))
tag=4;
double m,n;
int x,y;
if (tag==1)
{
m=2*(u-0.);
n=2*(v-0.);
x=(int)(pointxy[0].x*(1-m)*(1-n)+pointxy[1].x*(1-m)*n+pointxy[3].x *m*(1-n)+pointxy[4].x*m*n);
y=(int)(pointxy[0].y*(1-m)*(1-n)+pointxy[1].y*(1-m)*n+pointxy[3].y *m*(1-n)+pointxy[4].y*m*n);
mypoint[pointnum].x =x;
mypoint[pointnum].y =y;
pointnum++;
pDC->SetPixel (x,y,RGB(255,0,0));
}
if (tag==2)
{
m=2*(u-0.);
n=2*(v-0.5);
x=(int)(pointxy[1].x*(1-m)*(1-n)+pointxy[2].x*(1-m)*n+pointxy[4].x *m*(1-n)+pointxy[5].x*m*n);
y=(int)(pointxy[1].y*(1-m)*(1-n)+pointxy[2].y*(1-m)*n+pointxy[4].y *m*(1-n)+pointxy[5].y*m*n);
mypoint[pointnum].x =x;
mypoint[pointnum].y =y;
pointnum++;
pDC->SetPixel (x,y,RGB(255,0,0));
}
if (tag==3)
{
m=2*(u-0.5);
n=2*(v-0.);
x=(int)(pointxy[3].x*(1-m)*(1-n)+pointxy[4].x*(1-m)*n+pointxy[6].x *m*(1-n)+pointxy[7].x*m*n);
y=(int)(pointxy[3].y*(1-m)*(1-n)+pointxy[4].y*(1-m)*n+pointxy[6].y *m*(1-n)+pointxy[7].y*m*n);
mypoint[pointnum].x =x;
mypoint[pointnum].y =y;
pointnum++;
pDC->SetPixel (x,y,RGB(255,0,0));
}
if (tag==4)
{
m=2*(u-0.5);
n=2*(v-0.5);
x=(int)(pointxy[4].x*(1-m)*(1-n)+pointxy[5].x*(1-m)*n+pointxy[7].x *m*(1-n)+pointxy[8].x*m*n);
y=(int)(pointxy[4].y*(1-m)*(1-n)+pointxy[5].y*(1-m)*n+pointxy[7].y *m*(1-n)+pointxy[8].y*m*n);
mypoint[pointnum].x =x;
mypoint[pointnum].y =y;
pointnum++;
pDC->SetPixel (x,y,RGB(255,0,0));
}
// CDC *pDC=GetDC();
// pDC->SetPixel (x,y,RGB(255,0,0));
}
void CTrianglulationView::OnSelectPoint()
{
// TODO: Add your command handler code here
//CPoint selpoint[];
CDC *pDC=GetDC();
pDC->MoveTo (200,400);
pDC->LineTo (400,400);
pDC->LineTo (400,200);
pDC->LineTo (200,200);
pDC->LineTo (200,400);
/* int x,y;
x=300;
y=200;
while (y=360)
{
y=y+20;
pDC->SetPixel (x,y,1);
}
x=200;
y=300;
while (x=360)
{
x=x+20;
pDC->SetPixel (x,y,1);
}
x=200;
y=200;
while (x=260)
{
x=x+20;
while (y=260)
{
y=y+20;
pDC->SetPixel (x,y,1);
}
y=200;
}
x=300;
y=200;
while (x=360)
{
x=x+30;
while (y=260)
{
y=y+30;
pDC->SetPixel (x,y,1);
}
y=200;
}
x=200;
y=300;
while (x=260)
{
x=x+30;
while (y=360)
{
y=y+30;
pDC->SetPixel (x,y,1);
}
y=300;
}
x=300;
y=300;
while (x=360)
{
x=x+20;
while (y=360)
{
y=y+20;
pDC->SetPixel (x,y,1);
}
y=300;
}*/
int x,y;
x=200;
y=200;
while (x=400)
{
while (y=400)
{
pDC->SetPixel (x,y,RGB(255,0,0));
mypoint[pointnum].x =x;
mypoint[pointnum].y =y;
pointnum++;
y=y+40;
}
x=x+40;
y=200;
}
}
int CTrianglulationView::PointIsInside(int number1, int number2, int number3)
{
int i=0;
bool change1=1,change2=1,change3=1,change=1;
while ((i<(pointnum))&&(change==1))
{
if ((i!=number1)&&(i!=number2)&&(i!=number3))
{
change1=SameSide(number1,number2,number3,i);
change2=SameSide(number1,number3,number2,i);
change3=SameSide(number2,number3,number1,i);
if ((change1==1)&&(change2==1)&&(change3==1))
{
change=0;
return i;//yes
}
}
i++;
}
return 0;
}
bool CTrianglulationView::SameSide(int number1, int number2, int number3,int number4)
{
double b1,b2,b;
if ((number1==number3)||(number1==number4)||(number2==number3)||(number2==number4))
return 0;
b1=(mypoint[number1 ].x -mypoint[number2 ].x)*mypoint[number3].y
+(mypoint[number2 ].y -mypoint[number1 ].y)*mypoint[number3].x
+mypoint[number2].x *mypoint[number1].y -mypoint[number1].x*mypoint[number2].y;
b2=(mypoint[number1 ].x -mypoint[number2 ].x)*mypoint[number4].y
+(mypoint[number2 ].y -mypoint[number1].y)*mypoint[number4].x
+mypoint[number2].x *mypoint[number1].y -mypoint[number1].x*mypoint[number2].y;
b=b1*b2;
if (b>=0)
return 1;//在三角行边上
else
return 0;//不在三角行边上
}
void CTrianglulationView::Onuvtriangulation()
{
// TODO: Add your command handler code here
CDC *pDC=GetDC();
/* pDC->MoveTo (200,400);
pDC->LineTo (400,400);
pDC->LineTo (400,200);
pDC->LineTo (200,200);
pDC->LineTo (200,400);*/
/* x=200;
y=200;
while (y=360)
{
y=y+80;
pDC->SetPixel (x,y,RGB(255,0,0));
mypoint[pointnum].x =x;
mypoint[pointnum].y =y;
pointnum++;
}
x=200;
y=300;
while (x=360)
{
x=x+80;
pDC->SetPixel (x,y,RGB(255,0,0));
mypoint[pointnum].x =x;
mypoint[pointnum].y =y;
pointnum++;
}
x=200;
y=200;
while (x=260)
{
x=x+80;
while (y=260)
{
y=y+80;
pDC->SetPixel (x,y,RGB(255,0,0));
mypoint[pointnum].x =x;
mypoint[pointnum].y =y;
pointnum++;
}
y=200;
}
x=300;
y=200;
while (x=360)
{
x=x+80;
while (y=260)
{
y=y+80;
pDC->SetPixel (x,y,RGB(255,0,0));
mypoint[pointnum].x =x;
mypoint[pointnum].y =y;
pointnum++;
}
y=200;
}
x=200;
y=300;
while (x=260)
{
x=x+80;
while (y=360)
{
y=y+80;
pDC->SetPixel (x,y,RGB(255,0,0));
mypoint[pointnum].x =x;
mypoint[pointnum].y =y;
pointnum++;
}
y=300;
}
x=300;
y=300;
while (x=360)
{
x=x+80;
while (y=360)
{
y=y+80;
pDC->SetPixel (x,y,RGB(255,0,0));
mypoint[pointnum].x =x;
mypoint[pointnum].y =y;
pointnum++;
}
y=300;
}
y=200;
while (y=380)
{
pDC->SetPixel (200,y,RGB(255,0,0));
mypoint[pointnum].x =x;
mypoint[pointnum].y =y;
pointnum++;
y=y+80;
}
y=200;
while (y=380)
{
pDC->SetPixel (400,y,RGB(255,0,0));
mypoint[pointnum].x =x;
mypoint[pointnum].y =y;
pointnum++;
y=y+80;
}
x=200;
while (x=380)
{
pDC->SetPixel (x,200,RGB(255,0,0));
mypoint[pointnum].x =x;
mypoint[pointnum].y =y;
pointnum++;
x=x+80;
}
x=200;
while (x=380)
{
pDC->SetPixel (x,400,RGB(255,0,0));
mypoint[pointnum].x =x;
mypoint[pointnum].y =y;
pointnum++;
x=x+80;
}*/
Tpoint point1[36];
int x,y;
int number=0;
double i=0.;
double j=0.;
x=200;
y=200;
while (x=360)
{
while (y=360)
{
if ((x==280)&&(y==280)||(x==280)&&(y==320))
{
y=y+40;
}
else
{
i=((double)x-200)/(double)160;
j=(360-(double)y)/(double)160;
point1[number].x =fuzhix(i,j);
point1[number].y =fuzhiy(i,j);
point1[number].z =fuzhiz(i,j);
mypoint[pointnum].x =(int)(viewpoint.x +(point1[number].x -viewpoint.x )*viewpoint.z /(viewpoint.z -point1[number].z +0.0001))+300;
mypoint[pointnum].y =(int)(viewpoint.y +(point1[number].y -viewpoint.x )*viewpoint.z /(viewpoint.z -point1[number].z +0.0001));
pointnum++;
number++;
y=y+40;
}
}
y=200;
x=x+40;
}
}
void CTrianglulationView::Onll()
{
// TODO: Add your command handler code here
Ondevelopedsurface();
double i=0.;
double j=0.;
while (i=1.)
{
while (j=1.)
{
developpoint(i,j);
j=j+0.2;
}
i=i+0.2;
j=0.;
}
}