We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Relative position of 2 squares
Page Index Toggle Pages: 1
Relative position of 2 squares (Read 943 times)
Relative position of 2 squares
Jun 17th, 2009, 3:49pm
 
Hi all!

I'm working with TUIO library on a multitouch application and I'm stuck on a geometry problem.

I have some squares with an x, y, and angle properties defined by fiducials, and I want to know which face of each square (up, down, left, right) is in front of other square's face (up is suppossed 0º, so right is 90º, down 180º & left 270º).

So I need to know something like 'square "A" has its "up" face faced to "left" face of square "b"'.

I've tried to use the slope between 2 squares but it only tell me if they are faced horizontal or vertical (instead of a 0-360º value, tangent only gives me values between -90º & 90º).

Has anybody any suggestion in order to find a solution?

Thanks and regards!
Re: Relative position of 2 squares
Reply #1 - Jun 17th, 2009, 11:06pm
 
When trying to find the angle using atan((x2-x1)/(y2-y1)) it will only give you +-90. Try using atan2((x2-x1),(y2-y1)). It will give you the full 360 degrees. Hope thats what you mean.
Also I am not familiar with this library and have not completely understood what you're trying to do.
But the standard java math library works like that. It's also in the "Processing" Reference with examples.
Re: Relative position of 2 squares
Reply #2 - Jun 18th, 2009, 12:27am
 
kostino wrote on Jun 17th, 2009, 11:06pm:
Try using atan2((x2-x1),(y2-y1)). It will give you the full 360 degrees.


Careful...  atan2 takes the y coordinate as the first argument: atan2(y,x).

Also note that it returns an angle in radians, so you may need to convert it to degrees Wink
Re: Relative position of 2 squares
Reply #3 - Jun 18th, 2009, 3:12pm
 
Thanks for your help!

I've used atan2( (y2-y1),(x2-x1) ) to obtain the angle between 2 squares from 0 to TWO_PI.

Then, to know which face is faced to the other square has been easy looking at the value of this angle minus the square's angle.

Thanks and regards!
Smiley
Page Index Toggle Pages: 1