接線べくとるについて

フォーラム(掲示板)ルール
フォーラム(掲示板)ルールはこちら  ※コードを貼り付ける場合は [code][/code] で囲って下さい。詳しくはこちら

トピックに返信する


答えを正確にご入力ください。答えられるかどうかでスパムボットか否かを判定します。

BBCode: ON
[img]: ON
[flash]: OFF
[url]: ON
スマイリー: OFF

トピックのレビュー
   

展開ビュー トピックのレビュー: 接線べくとるについて

Re: 接線べくとるについて

#3

by usao » 7年前

オフトピック
実際に動作させたり,x1やy1を使用している箇所のコードをちゃんと読んだわけでもないので,offtopicとしますが,
line71,72のx1,y1の算出式が間違っているということはありませんか?

やりたいことから想像するに,この2行は dx(t)/dt, dy(t)/dt の計算なのかな,と思いますが,
もしそうなのであれば,ぱっと見の時点で以下が不自然に思えます.

・s^3が出てきそうな第2項 : 3 * s * ... のsが要らないのでは?
・x1とy1とで第1項の負号の有無が異なること : y1側も-が必要なのでは?

Re: 接線べくとるについて

#2

by Math » 7年前

実行すると”法線”を描いたのでは?。

コード:

Microsoft(R) Program Maintenance Utility Version 14.11.25508.2
Copyright (C) Microsoft Corporation.  All rights reserved.

        cl /c /TP /EHsc /I"d:\GL" /W3 c1.cpp
Microsoft(R) C/C++ Optimizing Compiler Version 19.11.25508.2 for x86
Copyright (C) Microsoft Corporation.  All rights reserved.

c1.cpp
        link /out:c1.exe /LIBPATH:"d:\GL" c1.obj
Microsoft (R) Incremental Linker Version 14.11.25508.2
Copyright (C) Microsoft Corporation.  All rights reserved.

        c1.exe
6.7082
5.97858
5.6045
5.30282
5.03388
4.875
4.89435
5.07168
5.31897
5.5863
6
6.7082
5.97858
5.6045
5.30282
5.03388
4.875
4.89435
5.07168
5.31897
5.5863
6

D:\z17c\GL\001\maingl>
画像

コメントを沢山書きましょう。追いかける時間がないので。

接線べくとるについて

#1

by adj » 7年前

個のコードはx,yの位置ベクトルを微分して位置ベクトルの描画に接戦ベクトルを書き込みたいと考えています。
が傾きがおかしくなってしまいます。
どこを訂正したら正しく描画できますか?

コード:

#include<iostream>        //C言語標準ライブラリのインクルード
#include<GL/glut.h>       //GLUTヘッダファイルのインクルード
#include<GL/gl.h>         //GLヘッダファイルのインクルード
#include<math.h>


double clt[4][3] =
{
    { 1,2,0 },
    { 2,3,0 },
    { 3,1,0 },
    { 5,1,0 },
};

//プロトタイプ宣言

void init(void);
void keyboard(unsigned char key, int x, int y);
void display(void);
void resize(int w, int h);


int main(int argc, char **argv)
{
    glutInit(&argc, argv);
    /* ウィンドウの生成 */
    glutInitDisplayMode(GLUT_RGBA | GLUT_SINGLE | GLUT_DEPTH);
    glutInitWindowPosition(200, 50);
    glutInitWindowSize(400, 400);
    glutCreateWindow(argv[0]);
    init();
    glutReshapeFunc(resize);
    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);
    glutMainLoop();

    return 0;
}

void keyboard(unsigned char key, int x, int y)
{
    switch (key) {
    case '\33':
    case 'q':
    case 'Q':
        exit(0);
        break;
    default:
        break;
    }
}


void display(void)
{

    float x, y, x1, y1, x2, y2, t, s;

    float length = 0;

    for (s = 0.0; s<1.1; s += 0.1)
    {

        glLineWidth(1.0f);
        glBegin(GL_LINE_STRIP);
        glColor3f(0.0, 1.0, 0.0);

        x = pow((1 - s), 3) * clt[0][0] + 3 * pow((1 - s), 2)*s * clt[1][0] + 3 * (1 - s)*pow(s, 2) * clt[2][0] + pow(s, 3) * clt[3][0];
        y = pow((1 - s), 3) * clt[0][1] + 3 * pow((1 - s), 2)*s * clt[1][1] + 3 * (1 - s)*pow(s, 2) * clt[2][1] + pow(s, 3) * clt[3][1];

        x1 = -3 * pow((1 - s) ,2) * clt[0][0]+  3 * s * (1 - s) * (1 - 3 * s) * clt[1][0] + 3 * s * (2 - 3 * s) * clt[2][0] + 3 * pow(s,2)*   clt[3][0];
        y1 =  3 * pow((1 - s), 2) * clt[0][1] + 3 * s * (1 - s) * (1 - 3 * s) * clt[1][1] + 3 * s * (2 - 3 * s) * clt[2][1] + 3 * pow(s, 2) * clt[3][1];

        length = sqrt(x1*x1 + y1*y1);

        std::cout << length << std::endl;


        for (x2 = x; x2 <= x + x1; x2 += 0.01)
        {
            if (x1 == 0)
            {
                glVertex2f(x, y);
                glVertex2f(x, y1);
            }
            else
            {
                y2 = (y1 / x1)*(x2 - x) + y;
                glVertex2f(x2, y2);
            }
        }
        glEnd();
    }


    glColor3f(1.0, 0.0, 0.0);

    glBegin(GL_LINE_STRIP);

    for (t = 0; t<1.1; t += 0.1)
    {

        x = pow((1 - t), 3) * clt[0][0] + 3 * pow((1 - t), 2)*t * clt[1][0] + 3 * (1 - t)*pow(t, 2) * clt[2][0] + pow(t, 3) * clt[3][0];
        y = pow((1 - t), 3) * clt[0][1] + 3 * pow((1 - t), 2)*t * clt[1][1] + 3 * (1 - t)*pow(t, 2) * clt[2][1] + pow(t, 3) * clt[3][1];

        glVertex2f(x, y);
    };

    glEnd();

    glFlush();

}


void resize(int w, int h)
{


    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    if (w <= h)
        glOrtho(-5.0, 20.0, -5.0*(GLfloat)h / (GLfloat)w,
            12.5*(GLfloat)h / (GLfloat)w, -10.0, 5.0);
    else
        glOrtho(-5.0*(GLfloat)w / (GLfloat)h,
            5.0*(GLfloat)w / (GLfloat)h, -5.0, 5.0, -5.0, 5.0);
    glScalef(3, 3, 3);
}


void init(void)
{
    glClearColor(0.0, 0.0, 0.0, 0.0);
}


ページトップ