I'm new on the Mathematics StackOverflow site. So please let me know, if you need more information on my topic or if it is offtopic maybe.
I have created an app. On this app a car is driving around on a specific area. The car can drive around 360 degrees. I'm checking if there is an obstacle right before the car (50px in front). I'm showing this check point by a line. It looks like this:
Now if the car is driving 30 degress to the top or to bottom, how can I position the line correctly?
Actually it looks like this:
I have the following facts to calculate the right position: The size of the image of the car is 50 x 25 px and the current position coordinates (left, top). I know the degree in which the car drives i.e. 30 deg. The size of the line is 50 x 1 px.
Can anyone give me a hint, how to position the line corectly? Thanks in advance.
UPDATE:
I'm having trouble calculating the center of the car. I thought it was too easy. If the car drives diagonally, it is not easy to calculate where the middle of the car is. The issue is, when the car is driving obliquely i.e. 30 degrees. Then I thought I could calculate the middle by dividing the image height and width / 2, but especially in height this is not correct.
The yellow point is actually my (wrong) calculation.
Here I have this information available + degree:
rect is the car image.




If you have the coordinates of the centre of the car, say $(x,y)$ then the line should start at coordinates $x+25\cos(\theta),y+25\sin(\theta)$ and end at coordinates $x+75\cos(\theta),y+75\sin(\theta)$.
These coordinates are given in pixels.
In your example $\theta$ is $-30$ degrees. The $-$ sign comes from the fact that the car turned towards the bottom-right rather than top-right.
Please note that if you use a software to compute $\cos$ and $\sin$, you need to make sure that it is calibrated in degrees. If it's calibrated in radians, use $\cos(\theta\cdot\frac{\pi}{180})$ instead.