How to change angle origin?

I have the following code:

 angle = Mathf.Atan2(target.y - center.y, target.x - center.x) * Mathf.Rad2Deg;

this produces an angle with origin on the direction (1,0) that looks like so:

how do I rotate the results of this code so the 0 points towards a different vector? For example modifiying it with the vector (-1,1) should yield these results:

thanks

From what you said, couldn’t you just add 225 degrees to your result?

I don’t really understand the problem, but if the above isn’t right, I’m guessing you could use a rotation matrix.

no, I want to add something to this code

angle = Mathf.Atan2(target.y - center.y, target.x - center.x) * Mathf.Rad2Deg;

that makes it yield an angle according to the 2nd picture instead of the 1st, based on a direction vector input

I still don’t quite understand what you’re asking, could you give an example input and output?

yes so take this example:

Where the green point is the target and the red point is the center

7596190--942310--Untitledc.png

angle = Mathf.Atan2(target.y - center.y, target.x - center.x) * Mathf.Rad2Deg;

this formula would result in something like angle = 150

however this is only because the frame of reference is taking 0Âş to be alligned to the direction (1,0)

if the frame of reference was alligned to (-1,1) the formula should give something like 10Âş for the same object position like here:
7596190--942313--Untitlesss.png
as you see the green point and the red point didnt move at all, but the angle result is different because the frame of reference at 0Âş is alligned differently

my goal is to make changes to the formula to somehow take into account the direction towards where 0 is pointing, and even though the target and the center might be in the same position, to get a different angle based on input of a different direction vector, being that the formula currently solves for (x1,y0)

It seems as if you realize “[the code you wrote]-140” would accomplish exactly what you want, but for fun you want to solve it in a different, more complicated way. You want to do it by modifying the 2 values inside Math.Atan2? Again, just for fun.

it could be solved like that but that is just hardcoding it? It wont be dynamic, what if I want it to allign to (0.24,3.5) how much should I subtract from the angle?

You can’t redefine the Cartesian plane. What’s the actual goal here? Give a real world example.

given a direction of movement (x,y) i want to trigger a method if the angle between the 2 objects is 10Âş ( not -10Âş)

Vector2.SignedAngle
You can use this to measure the signed angle between 2 directions. So your movement direction and green - red.

1 Like