1
vector<CGPoint>::iterator i;
vector<CGPoint>* bp = bicyclePad.bikePathPoints;
for(i = bp->begin(); i != bp->end()-3; i++){
    angle = atan2((*i).y/(*i).x) * 180/ PI;
}

I guess atan2 can only be used with floats and doubles. but I am trying to do it with an iterator. How would I go about doing the above?

John Riselvato
  • 12,854
  • 5
  • 62
  • 89

2 Answers2

4

atan2 takes two arguments:

angle = std::atan2(i->y, i->x) * 180 / PI;

should work fine. The correct overload (depending on what CGFloat typedefs to) will be chosen.

Note that i->x and i->y (which are strictly equivalent to (*i).x and (*i).y) are numbers (of type CGFloat), not iterators.

Alexandre C.
  • 55,948
  • 11
  • 128
  • 197
  • 1
    And I'll just note here that the reason it takes two arguments is that if `i->y` is nonzero, `i->x` is *allowed to be zero* even though that would nominally create a divide by zero error. – Mark B Jan 06 '12 at 16:42
  • 1
    @MarkB: Also, `atan2(-1, -1) != atan2(1, 1)`. You get the full oriented angle of the vector `(x, y)` with `atan2`, and not just the inverse tangent of the quotient. – Alexandre C. Jan 06 '12 at 16:57
2

This should work atan2(i->y, i->x) * 180 / PI

Tony The Lion
  • 61,704
  • 67
  • 242
  • 415