Calculate the coordinates of two points in a coordinate system knowing the angle

anglecoordinate systems

I have a coordinate system, where I can place points. This coordinate system takes as a reference also a 360 degree angle. Knowing the center of the coordinate system, the angle where I am pointing (in this case 90 degrees) and an opening of +- 30 degrees, how could I set two dots knowing the radio of the circumference (consider it as r).

enter image description here
I upload a picture, which I believe can make easier to understand better my question.

Is there any formula which I could use for any dot in any quadrant?

Data

Rotation  = clockwise
0 Degrees at the top
Center = 275, 275
Radius = r

Edit

I have tried to follow the mentioned answer but I do not get the expected results. In my real case, the angle of the dots are not ±30 degrees but +20, and +70. For reason, I have set the angles to a mod = 360.

After applying your method $$ (275 + r \sin \theta, 275 – r \cos\theta) $$
,
I have obtained completely different coordinates as I expected Coordinate1 = (263, 529) and Coordinate2 = (330, 523)

I attach a simple java code that I am using and I believe that could help to understand my process.

    sAngle = (angle + 20)%360;
    eAngle = (angle + 70)%360;

    int radiusArc = width/2 - 20;
    Point startCoordinate = new Point();
    startCoordinate.x = (int)(centerX + radiusArc*Math.sin(sAngle));
    startCoordinate.y = (int)(centerY - radiusArc*Math.cos(sAngle));

    Point endCoordinate = new Point();
    endCoordinate.x = (int)(centerX + radiusArc*Math.sin(eAngle));
    endCoordinate.y = (int)(centerY - radiusArc*Math.cos(eAngle));

As a last step, I attach an image which proves that all the values of the formula are the expected ones, but the results are not:

enter image description here

Best Answer

In general, to get from point $A$ to point $B$ in your coordinate system, if the distance from $A$ to $B$ is $r$ and the angular direction from $A$ to $B$ is $\theta$ (measured as shown in your figure), the movement from $A$ to $B$ is represented by a direction vector which is equal to

$$ (r \sin \theta, -r \cos\theta). $$

What this means is, to get the coordinates of $B$, add $r\sin\theta$ to the first coordinate of $A$ and subtract $r\cos\theta$ from the second coordinate. (I used the symbol $r$ here for the distance because later it will be the distance between the center dot and a red dot, which is the radius of the circle.)

So to get one of your red dots, first you take the angle where you are "pointing" (in your example, $90$ degrees). Call this angle $\theta_0$ so that we can plug in values other than $90$ degrees. Then consider the angle you will add or subtract for the "opening" (in your example, $30$ degrees). Call this angle $\Delta \theta$.

So the direction from the center dot to one red dot is $\theta_0 - \Delta\theta,$ and the direction from the center dot to the other red dot is $\theta_0 + \Delta\theta.$

So for the first red dot you can set $\theta = \theta_0 - \Delta\theta$ and then apply the formula

$$ (275 + r \sin \theta, 275 - r \cos\theta) $$

to get the coordinates of that dot. Then set $\theta = \theta_0 + \Delta\theta$ and apply the formula again to get the coordinates of the second dot.


In order to do this in software, you typically have to take care of one more detail. Most software expects the angle to be expressed in radians before you apply the sine or cosine functions. So if the desired angle is, for example, $110$ degrees, you must first multiply $110 \times (\pi/180)$ in order to get the number that you will pass to a function such as Math.sin.

Sometimes there is a shortcut for the conversion. For example, in Java you can use double angleRadians = Math.toRadians(angleDegrees). And then you can call Math.sin(angleRadians) and Math.cos(angleRadians).