I don't know that much about calculus, even less about Radians and polar coordinate systems. I need to find a point on the cartesian coordinate graph for my unity3d project. I know that the Mathf library with C# (or is it just Unity3d?) takes Radians as arguments, so I used the Mathf.Deg2Rad after finding my angle, then put that value into the right trig functions.
The problem is the results of these functions only give values in one quadrant. I need them rotate around the origin, with the mouse pointer (the details about the mouse are irrelevant in this question).
My code:
relativeMInput is a Vector2 containing the mouse position relative to the center of screen.
Vector2 chainDirection = new Vector2 (relativeMInput.x, relativeMInput.y); //Get opposite direction
float rad = Vector2.Angle (new Vector2 (relativeMInput.x, 0f), chainDirection) * Mathf.Deg2Rad; //Compute angle and convert to Radians because C# AND MANY OTHER language's math library foo's take radian arguments!
float dirCos, dirSin = 0f;
print ("RADIANS between center screen and mouse pointer is: " + rad+ " direction is:" + chainDirection );
//Assuming these angle calculations are right...
dirCos = Mathf.Cos (rad);
dirSin = Mathf.Sin (rad);
print ("DirCos = " + dirCos + "Sin = " + dirSin);
movementLerp = new Vector3 (cameraOffset * dirSin, cameraOffset * dirCos, ZCamOffset);
print ("MovementLerp = " + movementLerp);
movementLerp is a Vector3, which will be assigned to a gameobject's local position to LERP the camera to. CameraOffset and ZCamOffset specify the radius the camera will lerp to and how far back or forward the camera is.