Society of Robots - Robot Forum
Software => Software => Topic started by: mr roboto on March 21, 2012, 12:29:38 PM
-
hi all
i need some help with an algorythm.
if I have a robot with a sharp ir sensor mounted on a servo scanner and i want to tell the distance between 2 objects in front of me with the variables:
distance 1(the distance to the first objects edge)
distance 2(the distance to the second objects edge)
angel 1(angle to first objects edge(servo angle))
angle 2(i think you get it at this point.)
also how do i find the 2 distances?
THANKS
-
Hm, so you have two sides of a triangle and the angle between them...and you want to know the length of the third side?
Cosine law is your friend:
c^2 = a^2 + b^2 - 2abcos(theta)
Where theta = angle1 + angle2
MIKE
-
sorry but would you mind explaining it?
im not sure I understand.
-
Well, if c is the distance between the objects, a is what you measured to object 1, b is what you measured to object 2, and the angle that the servo had to turn to get from object a to object b is T, then the law of cosines says that:
c^2 = a^2 + b^2 + 2*a*b*cos(T)
It's sort of a generalization of Pythagorean Theorem, but it works when the triangle isn't a right angled triangle. You put your stuff into that equation and take the square root and that is the distance between the objects. Was that what you were looking for?
MIKE