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

📄 secondline.cpp

📁 电子画图板
💻 CPP
字号:
//直线SecondLine类 
//SecondLine.cpp

//包含的头文件
#include "stdafx.h"
#include "Coordinate.h"
#include "Shape.h"
#include "SecondLine.h"
#include <math.h>

//类实现
IMPLEMENT_SERIAL(SecondLine,Shape,1)

SecondLine::SecondLine(){
	a=0.0;
	b=0.0;
	c=0.0;
	expression.Format("y=%1.2lf*x^2+%1.2lf*x+%1.2lf",a,b,c);
}

SecondLine::SecondLine(double a,double b,double c){
	this->a=a;
	this->b=b;
	this->c=c;
	expression.Format("y=%1.2lf*x^2+%1.2lf*x+%1.2lf",a,b,c);
}

SecondLine::~SecondLine(){

}

void SecondLine::drawShape(CDC *pDC,Coordinate co){	//画二次函数
	//利用逐步逼近法画曲线
	double left=-200.0;            //最左边的坐标的横轴坐标(实际坐标)为left
								   //则最右边的坐标的横轴坐标(实际坐标)为-left
	double step=0.1;			   //设置逐步逼近的步长
    int size=(int)(2*(-left)/step)+1;	//计算出从最左边到最右边(以step为步长)的点数
	double x=left,y;
	CPoint * p=new CPoint[size];
	
	//得出一系列点的视图坐标,并放于一CPoing数组里
	for(int i=0;i<size;i++){
		y=a*x*x+b*x+c;  //y=f(x)	
		p[i]=co.getTrueAxis(x,y);	//坐标转换
		x+=step;
	}
	pDC->Polyline(p,size);		//利用一系列存放在点数组的点画线
	delete [] p;
}

void SecondLine::Serialize(CArchive &ar){	//串行化
	Shape::Serialize(ar);
	if(ar.IsStoring()){
		//storing
		ar <<a<<b<<c;
	}
	else{
		//loading
		ar >>a>>b>>c;
	}
}

⌨️ 快捷键说明

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