how to draw a line knowing the starting coordinate, line length x angle and y, angle

Question:

I am trying to draw a line knowing the starting coordinate, line length x angle and y, angle. I am trying to visualize the eye gaze direction of a human in a video.

For an example, I want to draw the blue lines here:

enter image description here

I already have the center point of the eye (start of the blue line), and I already have the x and y angle of the eye. How do I draw this line?

I’ve found a lot of tutorials on how to draw such lines (https://learnopencv.com/head-pose-estimation-using-opencv-and-dlib/), but they involve translation and rotation vectors. Is there a clean way to do this just using the known x/y angles?

Asked By: connor449

||

Answers:

no that not drawn with paint

It’s basically just math:

As far as I know, the height of the triangle is height = math.sinus(h) * l and its width is width = math.cos(h) * l.
I hope this help.

Answered By: ChronoX

Given a length r and an angle φ between the x-axis and your line to draw, you can calculate a coordinate for a point P(x, y) like this:

x = r * cos(φ)

y = r * sin(φ)

For example, a vertical line with r = 1; φ = 90° = π / 2 would return y = 1 * sin(π / 2) = 1

Then you can import your image in opencv and draw a line using cv2.line.

Answered By: Confused Learner