CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 16

Threaded View

  1. #10
    Join Date
    Jun 2012
    Posts
    8

    Question Re: Algoritme for doubling a line

    thanks again for the help

    so....i took your code and pluged it in to my application
    i work with Visual C++ 6.0 (old i know, but very efficiant )
    and i put your code behind a button

    my pixels cordinates are stored in two vectors X[800] and Y[800].
    i took the distance d = 10;

    and by the way you didn't talk about P1, so i assumed that it represents the pixel after P0

    so i took :
    P0 = X[i] and P1 = X[i+1]


    ofcourse i had to make some changes on the code and here is the transformed code :
    void CProjectDlg::OnButton7()
    {
    int d = 10;
    double dx ;
    double dy;
    double mag;
    double nx;
    double ny;

    CClientDC dc(this);

    for(int i = 0 ; i < 800 ; i++ )
    {

    dx = X[i+1] - X[i]; //P1x - P0x;
    dy = Y[i+1] - Y[i]; // P1y - P0y;
    mag = sqrt( dx*dx + dy*dy );

    /* if ( fabs(mag) < 1.e-6 ) // 10^-6 is an arbitrary small value
    {
    // the magnitude is so small that P0 and P1 are either the same point or so close to the same point
    // that no meaningful information can be derived on the derivative

    return false;
    }*/


    // derive the perpendicular vector, and normalize it

    nx = dy / mag;
    ny = -dx / mag;

    // derive coordinates of the displaced point Pd

    SetPixel(dc,(X[i] + d*nx),(Y[i] + d*ny),RGB(0,0,255));
    //Pdx = P0x + d*nx;
    //Pdy = P0y + d*ny;
    }
    }
    when i executed my code i got the result on picture 1
    and when i changed the Red Bold lines by this

    dx = X[i];
    dy = Y[i];

    i got the result on picture 2

    and as you can see, there is something wrong some where !

    can you basing on theses result give me an explanation or indicate what i missed ?

    thanks again !

    NB : sorry if the pictures quality is poor, i was fast and forgot to save them as bmps
    the original curve is the RED one and generated one is the Blue !
    Attached Images Attached Images
    • File Type: jpg 1.jpg (10.6 KB, 1713 views)
    • File Type: jpg 2.jpg (10.5 KB, 1822 views)
    Last edited by bimo; June 6th, 2012 at 07:46 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured