Loading...
Logo
Processing Forum

hi everyone ... i want to angle of  X ?
thank you :)

Replies(6)

http://www.wikihow.com/Find-the-Angle-Between-Two-Vectors

Or maybe use the

angleBetween() 

function, that should work...
probably use vectors A-O and B-O in the function

http://processing.org/reference/PVector_angleBetween_.html
thank you janjacobsv .first link is not my way :) 
and how can i do with  angleBetween() code i dont know ? please some help...
Have you tried? maybe you can show your code and I can check what goes wrong.
It can be a bit tricky with vectors, You have three vectors discribing point in space, e.g (5,4)
angleBetween works on the directional vectors, to get the dirctional vector from point O to point A you have to substract them: O-A (or A.x-O.x, A.y-O.y)
do this as well for directional vector B-O and put those in the angle between:
angleBetween(A-O, B-O)
thank you for advise  janjacobsv :) 

is it working ...


Copy code
  1. PVector o = new PVector(40, 50); 
  2. PVector a = new PVector(40, 0);
  3. PVector b = new PVector(80, 50); 

  4. float aoX = a.x-o.x;
  5. float aoY = a.y-o.y;

  6. float boX = b.x-o.x;
  7. float boY = b.y-o.y;

  8. PVector bo = new PVector(boX,boY);
  9. PVector ao = new PVector(aoX,aoY); 

  10. float m = PVector.angleBetween(ao,bo);
  11. println(int(degrees(m)));  

  12. line(a.x,a.y,o.x,o.y);
  13. line(b.x,b.y,o.x,o.y);

The code calculates the angle between the vectors correctly.