• 12
• 27
• 9
• 9
• 20

# find components distances from 2 points on a plane n

This topic is 1208 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Take a look on at the image on the right.I need to find y and x distances between two dots (points) that lie on this plane i know the y and x directions and the points poisition, surface normal is also known.

I need this to find angle between these two points (and i need it to e between 0..360) maybe someone knows better formula to achieve this.

##### Share on other sites
You have to define a coordinate frame on the plane. Both the distances along these coordinates and the angle depends on this arbitrary choice.

##### Share on other sites

Take a look on at the image on the right.I need to find y and x distances between two dots (points) that lie on this plane i know the y and x directions and the points poisition, surface normal is also known.

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.

I need this to find angle between these two points (and i need it to e between 0..360) maybe someone knows better formula to achieve this.

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.

##### Share on other sites

Adding to Brother Bob's post (thumbs up):

You can't determine an angle between two points. An angle would be between two lines or vectors. You haven't provided enough information to determine what "angle" you're looking for.

##### Share on other sites

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:

Edited by WiredCat

##### Share on other sites

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))

The projection of a vector onto another vector is calculated using the dot product.

xlen = dot(B-A, x)
ylen = dot(B-A, y)


Buckeye

Oh indeed i can

What you are calculating is the angle between the vector cpos-pos and what appears to be the X-axis. You are therefore not calculating the angle between two points, but between two vectors, just what Buckeye stated. One vector is cpos-pos and the other vector is implicitly hardcoded as the X-axis.

Edited by Brother Bob