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;
/* 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
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 !
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.