【发布时间】:2015-02-20 01:12:07
【问题描述】:
所以我试图绘制这个欧拉积分函数的输出:
typedef double F(double,double);
using std::vector;
void euler(F f, double y0, double a, double b, double h,vector<POINT> Points)
{
POINT Pt;
double y_n = y0;
double t = a;
for (double t = a; t != b; t += h )
{
y_n += h * f(t, y_n);
Pt.x = t; // assign the x value of the point to t.
Pt.y = y_n; // assign the y value of the point to y_n.
Points.push_back(Pt);
}
}
// Example: Newton's cooling law
double newtonCoolingLaw(double, double t)
{
return t; // return statement ends the function; here, it gives the time derivative y' = -0.07 * (t - 20)
}
我正在尝试在 Win32 应用程序中使用 Polyline() 函数,所以我在 WM_PAINT 的情况下这样做:
case WM_PAINT:
{
hdc = BeginPaint(hWnd, &ps);
//Draw lines to screen.
hPen = CreatePen(PS_SOLID, 1, RGB(255, 25, 5));
SelectObject(hdc, hPen);
using std::vector;
vector<POINT> Points(0);
euler(newtonCoolingLaw, 1, 0, 20, 1,Points);
POINT tmp = Points.at(0);
const POINT* elementPoints[1] = { &tmp };
int numberpoints = (int) Points.size() - 1 ;
Polyline(hdc,elementPoints[1],numberpoints);
当我将 I/O 重新路由到控制台时,以下是变量的输出:
我可以使用MovetoEx(hdc,0,0,NULL) 和LineTo(hdc,20,20) 在屏幕上绘制预期的线条,但由于某种原因,这些功能都不适用于我的vector<POINT> Points。有什么建议吗?
【问题讨论】: