⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cb2line.cpp

📁 实现了区域填充已经其他画线功能
💻 CPP
字号:
// B2_Line.cpp: implementation of the CB_Line class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "GraphExp.h"
#include "CB2Line.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CB_Line::CB_Line()
{
//	m_BezierN=new CPoint[100];
	mark=0;
}

CB_Line::CB_Line(CPoint P1,CPoint P2,CPoint P3,COLORREF color)
{
//	m_BezierN=new CPoint[100];
	 c_color=color;
	 p1=P1;
	 p2=P2;
	 p3=P3;
	 mark=0;
}

CB_Line::CB_Line(CPoint P1,CPoint P2,CPoint P3,CPoint P4,COLORREF color)
{
//	m_BezierN=new CPoint[100];
	 c_color=color;
	 p1=P1;
	 p2=P2;
	 p3=P3;
	 p4=P4;
 	 mark=0;
}

CB_Line::CB_Line(CPoint *P,int n,COLORREF color)
{
	
	int i;
 	m_numBezierN=n;
	m_BezierN=new CPoint[n+1];
	for(i=0;i<=n;i++)
		m_BezierN[i]=P[i];
	c_color=color;
	mark=1;

}

CB_Line::~CB_Line()
{
//	delete [] m_BezierN;
}

void CB_Line::B2_Line(CDC *pDC)
{
	int x0=p1.x,y0=p1.y;
	int x1=p2.x,y1=p2.y;
	int x2=p3.x,y2=p3.y;
	float i,t,n=1000;
	i=1/n;
	double px,py;
	CPoint pp;

	px=x0;
	py=y0;

	for(t=i;t<=1;t+=i)
	{
		pp.x=px+0.5;
		pp.y=py+0.5;
		pDC->SetPixel(pp,c_color);
		px=(t-1)*(t-1)*0.5*x0+0.5*(-2*t*t+2*t+1)*x1+0.5*t*t*x2;
		py=(t-1)*(t-1)*0.5*y0+0.5*(-2*t*t+2*t+1)*y1+0.5*t*t*y2;
	}
}

void CB_Line::Bezier2(CDC *pDC)
{
	int x0=p1.x,y0=p1.y;
	int x1=p2.x,y1=p2.y;
	int x2=p3.x,y2=p3.y;
	float t,i,i2;
	float n=1000;
	i=1.0/n;
	i2=i*i;
	float px,py;
	float x00,y00,x01,y01;

	x00=x0-2*x1+x2;
	y00=y0-2*y1+y2;
	x01=i2*(x0+x2)+2*(i-i2)*x1-2*i*x0;
	y01=i2*(y0+y2)+2*(i-i2)*y1-2*i*y0;
	x00=2*i*x00;
	y00=2*i*y00;
	px=x0;
	py=y0;

	for( t=i;t<=1;t+=i)
	{
		pDC->SetPixel(int(px+0.5),int(py+0.5),c_color);
		px=px+t*x00+x01;
		py=py+t*y00+y01;
	}
}

void CB_Line::B3_Line(CDC *pDC)
{
	int x0=p1.x,y0=p1.y;
	int x1=p2.x,y1=p2.y;
	int x2=p3.x,y2=p3.y;
	int x3=p4.x,y3=p4.y;
	float i,t,t3,t2,n=1000;
	i=1/n;
	const	float f=float(1.0/6);
	float px,py;
	px=x0;
	py=y0;
	for(t=i;t<=1;t+=i)
	{
		t3=t*t*t;
		t2=t*t;
		pDC->SetPixel(int(px+0.5),int(py+0.5),c_color);
		px=f*((-t3+3*t2-3*t+1)*x0+(3*t3-6*t2+4)*x1+(-3*t3+3*t2+3*t+1)*x2+t3*x3);
		py=f*((-t3+3*t2-3*t+1)*y0+(3*t3-6*t2+4)*y1+(-3*t3+3*t2+3*t+1)*y2+t3*y3);
	}
}

void CB_Line::Bezier3 (CDC *pDC)
{
	int x0=p1.x,y0=p1.y;
	int x1=p2.x,y1=p2.y;
	int x2=p3.x,y2=p3.y;
	int x3=p4.x,y3=p4.y;
	float i,t,n=1000;
	i=1/n;
	float px,py;
	px=x0;
	py=y0;
	for(t=i;t<=1;t+=i)
	{
		pDC->SetPixel(int(px+0.5),int(py+0.5),c_color);
		px=(1-t)*(1-t)*(1-t)*x0+t*t*t*x3+3*t*(1-t)*(1-t)*x1+3*t*t*(1-t)*x2;
		py=(1-t)*(1-t)*(1-t)*y0+t*t*t*y3+3*t*(1-t)*(1-t)*y1+3*t*t*(1-t)*y2;
	}
}

void CB_Line::BezierN(CDC *pDC)
{
	CPen Newpen1(PS_SOLID,1,c_color);
	CPen *pOldPen1=pDC->SelectObject(&Newpen1);

	int x,y,i,j,k=40,a,b;
	double	t,t1,u,v;
	double temp,temp1,temp2,bi;
	t=1.0/k;
	a=m_BezierN[0].x;
	b=m_BezierN[0].y;
	//pDC->MoveTo(a,b);
	for(j=1;j<k;j++ )
	{
		pDC->MoveTo(a,b);
		t1=j*t;
		u=t1;v=1-u;
		x=0;y=0;
		for(i=0;i<=m_numBezierN;i++)
		{
			temp=double(fac(m_numBezierN)/fac(i)/fac(m_numBezierN-i));
			temp1=powi(u,i);
			temp2=powi(v,m_numBezierN-i);
			bi=temp*temp1*temp2;
			x=x+bi*m_BezierN[i].x;
			y=y+bi*m_BezierN[i].y;
		}
		pDC->LineTo(x,y);
		a=x;
		b=y;
	}
	pDC->SelectObject(pOldPen1);
}

long CB_Line::fac(int m)
{
	int i;
	long temp=1;
	if(m==0)	return 1;
	else
	{
		for(i=2;i<=m;i++)
			temp=temp*i;
	}
	return temp;
}

double CB_Line::powi(double v, int k)
{
	double temp=1.0;
	if(k==0||v==0)	return 1;
	else	
	{
		for(int i=1;i<=k;i++)
			temp=temp*v;
	}

	return temp;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -