0

ベクトルに含まれる点の間に線分を描画し、ウィンドウに表示したいと考えています。

現在、これは私が持っているものです:

case WM_PAINT:
    hdc = BeginPaint(hWnd, &ps);
  //Draw lines to screen.
    using std::vector;
    using std::iterator;
    extern vector<int> euler_time;
    extern vector<int> euler_soln;
    hPen = CreatePen(PS_SOLID, 1, RGB(255, 25, 5));
    SelectObject(hdc, hPen);
    for(std::vector<int>::size_type i = 0; i != euler_time.size(); i++){
    MoveToEx(hdc,euler_time[i],euler_soln[i],NULL);
    LineTo(hdc,euler_time[i],euler_soln[i]);
    }
    EndPaint(hWnd, &ps);

これは、標準の Win32 アプリケーションを作成するときに生成される、より大きな .CPP ソース ファイルに含まれています。

ご覧のとおり、私のアイデアは、forループを使用してベクトルを反復処理し、and を使用LineToMoveToExて次のポイントに移動し、前のポイントから線を描画することでした。

現在、エラーのない完全に空白のウィンドウが表示されます。提案?

編集:

したがって、以下のコメントに記載されているブレーク ポイント メッセージは、外部ベクターをロードしたことが原因であると推測しています。ベクトルは、for別の .CPP ファイルのループの出力です。

    using std::vector;
    using std::iterator;
    extern vector<int> euler_time;
    extern vector<int> euler_soln;

そして、他の .CPP ファイルのループ:

for (double t = a; t < b; t += h )
{
    std::cout << std::fixed << std::setprecision(3) << t << " " << y << "\n";
    euler_time.insert (euler_time.begin(),t); // Insert the values of t and y into the respective vectors.
    euler_soln.insert (euler_soln.begin(),y);
    y += h * f(t, y);
}

編集2:

そこで、Polyline API から始めました。const POINT*という型の配列を作成し、それにPt値を代入しようty_nしました。Polyline次に、配列から描画するように呼び出して指示しました。

エラーが発生せず、空白のウィンドウが再び表示されます。

ウィンドウ CPP ファイルから:

    extern const POINT* Pt;
  //Draw lines to screen.
    hPen = CreatePen(PS_SOLID, 1, RGB(255, 25, 5));
    SelectObject(hdc, hPen);
    Polyline(hdc,Pt,10);

他の CPP ファイルから:

const POINT * Pt;
void euler(F f, int y0, int a, int b, int h ) // defines a class of type     "void" (returns nothing); gives it parameters: function F, doubles: y0, a, b, h
{
int y_n = y0;
int t = a;
for (int t = a; t < b; t += h ) // creates a for loop beginning with time t = a and ending with t ~= b with stepsize h.
{
    std::cout << std::fixed << std::setprecision(3) << t << " " << y_n << "\n"; // Calls the standard output from std, with floating-point numbers with precision 3; assigns the variable t, then a space, then variable y, then a new line.
    LONG x = t;
    LONG y = y_n;
    y_n += h * f(t, y_n); // y increases by h * f(t,y) where f is the derivative y' until the condition is met y ~= b.
}
std::cout << "done\n"; // Print "done"
}

編集3:

私は今vector<POINT>、ポイント値を持つベクトルを作成するために使用しようとしています. ただし、私の試行では次のエラーが発生します。

6   IntelliSense: no instance of overloaded function "std::vector<_Ty, _Alloc>::insert [with _Ty=POINT, _Alloc=std::allocator<POINT>]" matches the argument list
        argument types are: (std::_Vector_iterator<std::_Vector_val<std::_Simple_types<POINT>>>, double)
        object type is: std::vector<POINT, std::allocator<POINT>>   c:\Users\ahlroth\Documents\Visual Studio 2012\Projects\Euler\Euler\eulerclass.cpp   22

私のコードは以下の通りです:

using std::vector;
vector<POINT> Pt;
POINT euler(F f, double y0, double a, double b, double h, vector<POINT> Pt) // defines a class of type "void" (returns nothing); gives it parameters: function F, doubles: y0, a, b, h
{
    double y_n = y0;
    double t = a;
    for (double t = a; t < b; t += h ) // creates a for loop beginning with time t = a and ending with t ~= b with stepsize h.
{
    std::cout << std::fixed << std::setprecision(3) << t << " " << y_n << "\n"; // Calls the standard output from std, with floating-point numbers with precision 3; assigns the variable t, then a space, then variable y, then a new line.
    Pt.insert(Pt.begin(),t);
    y_n += h * f(t, y_n); // y increases by h * f(t,y) where f is the derivative y' until the condition is met y ~= b.
}
return Pt;
std::cout << "done\n"; // Print "done"

}

エラーは次の行です。 Pt.insert(Pt.begin(),t);

編集:答えについては、この投稿を参照してください。

4

1 に答える 1

2

これは、長さゼロの線分を描いているためです。

最初のポイントでのみ MoveTo を実行し、残りのポイントで LineTo を実行します。

于 2015-02-05T19:39:19.820 に答える