24

I have a point and an angle in OpenCV, how can I draw that using those parameters and not using 2 points?

Thanks so much!

DualSim
  • 279
  • 2
  • 4
  • 7
  • I think [this question](https://stackoverflow.com/questions/1571294/line-equation-with-angle) has the answer you are looking for. HTH – scap3y Mar 07 '14 at 14:19
  • What you mean with drawing 'that' ? Do you want to draw a line with that angle ? If that so, you can not draw a line without two points. If you want to draw a line with constant length in each case, you should find the second point having this constant length with respect to first point, than draw the line with this points. Please open up what you want. – yutasrobot Mar 07 '14 at 15:49
  • http://stackoverflow.com/questions/18782873/houghlines-transform-in-opencv – Engine Mar 07 '14 at 16:04
  • Thanks so much. "That" I mentioned talking about line. I'd like do that because it will be better for the process. I have goods angles and points and I'd like to draw them. If it's not possible I'll need to compute the two points and it'll not good for my program. – DualSim Mar 07 '14 at 18:13

1 Answers1

50

Just use the equation

x2 = x1 + length * cos(θ)
y2 = y1 + length * sin(θ) 

and θ should be in radians

θ = angle * 3.14 / 180.0

In OpenCV you can rewrite the above equation like

int angle = 45;
int length = 150;
Point P1(50,50);
Point P2;

P2.x =  (int)round(P1.x + length * cos(angle * CV_PI / 180.0));
P2.y =  (int)round(P1.y + length * sin(angle * CV_PI / 180.0));

Done!

CodeBender
  • 35,668
  • 12
  • 125
  • 132
Haris
  • 13,645
  • 12
  • 90
  • 121