How can I calculate the angle of a line/vector if the center of the image is not (0,0)?

48 Views Asked by At

Simple image about the problem

How can I calculate the alpha? My center of the image is (320,240) because it is a 640x480 image and the upper left corner is the (0,0).

I tried to calculate it with the parametric equation ( x = r * cos(alpha) ) and it worked until I reached alpha > 180 degrees.

How can I calculate it after 180 degrees?

In code: dist = math.sqrt((math.pow((centerDart[0] - centerPoint[0]),2) + math.pow((centerDart[1] - centerPoint[1]),2)))

I wanted to transform the point with this: centerDart[0]-320

angleFromCos = round(math.degrees(math.acos((centerDart[0]-320)/dist)),2)

1

There are 1 best solutions below

4
On

Who cares what the center of the image is? You have two points on that line, which are, according to the image, $\;(320,\,240)\;,\;\;(0,\,480)\;$ , so you can already calculate the line's slope:

$$m:=\frac{480-240}{320}=\frac{24}{32}=\frac34$$

so the angle between the line and any line parallel to the $\;x-$ axis is given by $\;\beta=\arctan\frac34\;$ , and thus your angle is $\;\alpha=\beta+180^\circ\;$