Brother Bob:
Project the vector between the two points onto the X and Y vectors. Just ensure that the X and Y vectors are normalized.
The projections are the component along the X and Y directions, respectively - ? you mean after projection i take the vector length? X len = veclength(Xvec* Projected(B-A))
I will take a guess that you don't need the angle, but rather that you want the angle because you don't know a solution in linear algebra. You have a vector-based problem, and solutions rarely involve angles. Describe your problem instead and we'll propose a vector solution that isn't dependent on angles.
Brrrrp wrong i need to output the angle after getting this new x y
Buckeye
Oh indeed i can
template <class type> long double __fastcall GetLongitudeLD(t3dpoint<type> cpos, t3dpoint<type> pos) //poludniki (Dlugosc)
{
long double angle;
angle = n2dGetPolarCoordAngleAD((long double)cpos.x-(long double)pos.x,(long double)cpos.z-(long double)pos.z) / (pild*2.0);
//
angle = -360.0*angle;
angle = VALIDUJ(angle)+90.0; //this may show the error since i copied wrong function that required 90 degree rotation in order to get proper angles
angle = VALIDUJ(angle);
return angle;
}
long double __fastcall n2dGetPolarCoordAngleAD(double x,double y)
{
if ( (x == 0) && (y > 0) ) { return 3.1415926535897932384626433832795/2.0; }
if ( (x == 0) && (y < 0) ) { return 3.0*3.1415926535897932384626433832795/2.0; }
if (x == 0) return - 1000.0;
long double k; k = (long double)y / (long double)x;
if ( (x > 0) && (y >= 0) ) { return atanl(k); }
if ( (x > 0) && (y < 0) ) { return atanl(k)+2.0*3.1415926535897932384626433832795; }
if (x < 0) { return atanl(k)+3.1415926535897932384626433832795; }
//last versions were without .0 just simple 2 division
return - 1000.0;
}
template <class type> type __fastcall VALIDUJ(type angle2)
{
type angle = angle2;
int kat=(int)angle2;
kat=kat/360;
if (angle < 0 )
{
angle = angle + (type)(kat+1)*360.0;
}
if (angle >= 360)
{
angle = angle - (type)kat*360.0;
}
return angle;
}
where cpos is blue point position, and pos is red dot position
heres a helper drawing: