Discussion about math, puzzles, games and fun. Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ π -¹ ² ³ °

You are not logged in.

- Topics: Active | Unanswered

**model****Member**- Registered: 2011-08-10
- Posts: 142

Angle in between two points with x , y coordinates

//two points with x and y coordinates

int x1 = 100 , y1 = 50, x2 =250, y2 =70;

//distance b/w them

int X = x1 - x2;

int Y = y1 - y2;

int x = pow((double)X,2);

int y = pow((double)Y,2);

int d = abs( sqrt( (double)x + (double)y ) );

int angleInRadian = atan2((double)Y,(double)X); //angle in radian

int angleInDegree = angleInRadian * 180 / PI;

cout<<"Radian Angle between two Points .."<< angleInRadian <<endl;

cout<<"Degree Angle between two Points .."<< angleInDegree <<endl;

Output:

Radian Angle between two Points ..-3

Degree Angle between two Points ..-171

Edited code:

Well I changed my condition ,..

if( angleInDegree >240 || angleInDegree > 45)

{

cout<<"move to right side.."<<endl;

}

else if ( angleInDegree <330 && angleInDegree > 91 )

{

cout<<"move to left side.."<<endl;

}

but i ma afraid if angle straight mean 180 or angle is < then 45 ... I did not consider that ...

Modified Condition :

Now i modify the condition that better handle all 4 quadrant.

modified condition for the above code:

if( angleInDegree <225 || angleInDegree > 0)

{

cout<<"move to right side.."<<endl;

}

else if ( angleInDegree <360 || angleInDegree > 91 )

{

cout<<"move to left side.."<<endl;

}

I think its better condition.. that cover complete quadrant ..

Well Is the condition still need to modify ?

Please help me thanks

*Last edited by model (2011-08-10 17:35:00)*

Maths is Doctor that make our life easy ..

https://www.facebook.com/groups/Maths.GIS/

Offline

**bob bundy****Moderator**- Registered: 2010-06-20
- Posts: 6,791

hi model

I've got lots of questions about this:

(i) Why have you calculated the distance between the points?

(ii) What language is this in?

(iii) double ? Does this calculate with double precision?

(iv) I got confused about what angle you wanted. I've now made a diagram (see below). Please confirm this is the angle you want.

Your formula for the angle seems to be

I thought you wanted

(v) The function atan will return the 'principle value' ; most likely this will be an angle between -90 and +90.

If you want to get a positive angle for any co-ordinates, you'll need to test the sign of the answer rather than worry about the size of the angle.

(vi) I do not understand the output "move to right/left side" means. Please explain what you are trying to achieve here.

(vii) You have an angle of 171 for these co-ordinates. I make it 10.9 degrees. Are we talking about the same thing?

Please post again,

Bob

*Last edited by bob bundy (2011-08-10 20:23:22)*

You cannot teach a man anything; you can only help him find it within himself..........Galileo Galilei

Offline

**model****Member**- Registered: 2011-08-10
- Posts: 142

Hi Bob,

I hope you are fine . Sorry, for late reply .

I am using c++ VS 2010.

Actually i need to find my hand motion direction.

So, i find the angle .. Is that correct ?

Then i need to detect the hand direction like right side mean East , or left side == west .

So, i applied condition by considering Cartesian coordinates . Is that condition right ?

yes angle is in double .

Your statement : "The function atan will return the 'principle value' ; most likely this will be an angle between -90 and +90."

if the atan return angle in between 90 and -90 . then i think its good to check that finger move to right(east side) or left(west side) .

What do you say ?

Please suggest me .

Thanks

Cheers,

Rabi...:)

Maths is Doctor that make our life easy ..

https://www.facebook.com/groups/Maths.GIS/

Offline

**model****Member**- Registered: 2011-08-10
- Posts: 142

Well @Bob , I changed my condition regarding angle direction to eat side or west side .

if( angleInDegree <=90 || angleInDegree > =0)

{

cout<<"move to right side.."<<endl;

}

else if ( angleInDegree <=180 || angleInDegree >= 91 )

{

cout<<"move to left side.."<<endl;

}

Is that now ok ?

*Last edited by model (2011-08-16 20:33:57)*

Maths is Doctor that make our life easy ..

https://www.facebook.com/groups/Maths.GIS/

Offline

**bob bundy****Moderator**- Registered: 2010-06-20
- Posts: 6,791

hi model,

I was just making a new diagram when you posted.

Do you just want to know whether the movement is left(west) or right(east) ?

If so you can just look at the sign of x1 - x2.

If x1 - x2 is + then the movement is right(east).

If x1 - x2 is - then the movement is left(west).

You can say north and south as well, by subtracting the y co-ordinates.

If you look at my four diagrams.

When AB goes up ( + gradient) the angle comes out between 0 and 90

When AB goes down ( - gradient) the angle comes out between 0 and -90.

So I think this is not the easiest way to tell left / right.

atan will not give an angle over 90.

Bob

*Last edited by bob bundy (2011-08-16 20:54:11)*

You cannot teach a man anything; you can only help him find it within himself..........Galileo Galilei

Offline

**model****Member**- Registered: 2011-08-10
- Posts: 142

Hi Bob,

I did as you said . about the right and left side ,

But my finger is continuously moving from left to right in different angles.

and i set

if x1-x2 > 0 then Print 1( right side movement )

else if x1 -x2 < 0 then Print -1 ( left side movement mean)

else Print 0 (moment in no specific direction .)

But Since my hand or finger whatelse moving in different direction. So, i think angle is also important.

btw, Can you please tell me formula for angle between 4 points

i found this formula:

abs(p1.y-p2.y)/sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));

I think above formula is good to find the angle in specific direction and distance .

What do you say ?

Maths is Doctor that make our life easy ..

https://www.facebook.com/groups/Maths.GIS/

Offline

**bob bundy****Moderator**- Registered: 2010-06-20
- Posts: 6,791

hi model,

I'm confused. What happens after you've printed move right or move left?

Are you trying to 'home in' on a point?

It would help me to understand if you could go back before you tried to calculate anything.

What is the purpose of it all? What is this a part of?

Bob

You cannot teach a man anything; you can only help him find it within himself..........Galileo Galilei

Offline

**model****Member**- Registered: 2011-08-10
- Posts: 142

Hi Bob,

Sorry, I did not read your recent message .

As i told you, I am doing project hand motion direction . i need to find an direction of my hand motion . like moving hand angle in which quadrant .

I got an idea .

If my hand have location current and previous say A(x1,y1) and B(x2,y2) .. then to find an angle i need third point in plane .

So, i am thinking that if we consider Origin as third point say O(x3,y3) .

then using vector concept . we can get the hand angle in plane .

Right ? ok ?

And we can get two vectors says OA and OB ,. and then we can find angle of hand motion . right ???

Is that ok ??

Please guide me thanks

Model

*Last edited by model (2011-08-17 05:18:30)*

Maths is Doctor that make our life easy ..

https://www.facebook.com/groups/Maths.GIS/

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 92,942

Hi model;

i found this formula:

abs(p1.y-p2.y)/sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));

Isn't that two points?

btw, Can you please tell me formula for angle between 4 points

What are you asking here is for the angle between two line segments that are determined by 4 points. Is this correct?

You also need to add an interactive geometry program to your toolbox. C++ is not a tool for visualizing graphics. I suggest the latest Geogebra.

**In mathematics, you don't understand things. You just get used to them.**

**I agree with you regarding the satisfaction and importance of actually computing some numbers. I can't tell you how often I see time and money wasted because someone didn't bother to run the numbers.**

Offline

**bob bundy****Moderator**- Registered: 2010-06-20
- Posts: 6,791

hi model

project hand motion direction

Sorry, but I don't understand what you mean.

Is this part of a bigger program? If so, what is that about?

Do you have an algorithm / flow chart / object diagram to show how this fits together?

I'm not sure how to help you because I'm not sure what to want to achieve?

Bob

Offline

**gAr****Member**- Registered: 2011-01-09
- Posts: 3,479

Hi model,

From your description, I guess that you are writing a gesture recognition software.

When a person points to left or right, you approximate two extreme points and find the angle between them.

Is my guess correct?

But can only two points be sufficient to distinguish the direction?

"Believe nothing, no matter where you read it, or who said it, no matter if I have said it, unless it agrees with your own reason and your own common sense" - Buddha?

"Data! Data! Data!" he cried impatiently. "I can't make bricks without clay."

Offline