Skip to content
View in the app

A better way to browse. Learn more.

WRobot

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Help with some trigonometry,

Featured Replies

Hello, 

i am trying to figure out how to get a facing target from the vector3, the angle, and targets vector3.

We have the following data:
- Our Vector3 Position (X, Y, Z) (100, 100, 0)
- Our Current Facing Angle (Pitch, Yaw) (90, 180)
- Targets Vector3 Position (X, Y, Z) (200, 200, 0)

How do we calculate the Angle (Pitch, Yaw) that I would need to reach to be facing our target.

I just need the math function to take the input and output the info i need. the rest i can do.

-Smokie

 

 

I believe this should work:

        /// <summary>
        /// Used to get the facing from two positions based on the origin rotation.
        /// </summary>
        /// <param name="from">The 1. position.</param>
        /// <param name="to">The 2. position.</param>
        /// <param name="originRotation">The origin rotation.</param>
        /// <returns>Negative radian on the right; positive on the left.</returns>
        public float FacingCenter(WoWPoint from, WoWPoint to, float originRotation)
        {
            var face = NormalizeRadian(Atan2Rotation(from, to) - originRotation);
            if (face < Math.PI)
                return -face;
            return NormalizeRadian(originRotation-Atan2Rotation(from, to));
        }

        /// <summary>
        /// Used to normalize the input radian.
        /// </summary>
        /// <param name="radian">The radians to normalize.</param>
        public float NormalizeRadian(float radian)
        {
            if (radian < 0.0)
                return (float) (-(- radian % (2.0 * Math.PI)) + 2.0 * Math.PI);
            return radian % 6.283185f;
        }
    
        /// <summary>
        /// Used to calculate atan2 of to positions.
        /// </summary>
        /// <param name="from">Position 1.</param>
        /// <param name="to">Position 2.</param>
        /// <param name="addRadian">Radians to add.</param>
        /// <returns></returns>
        public static float Atan2Rotation(WoWPoint from, WoWPoint to, float addRadian = 0)
        {
            return (float) Math.Atan2(to.Y - from.Y, to.X - from.X) + addRadian;
        }

        /// <summary>
        /// Used to calculate new position by parameter.
        /// </summary>
        /// <param name="from">The position to calculate from.</param>
        /// <param name="rotation">The rotation of the object in radians.</param>
        /// <param name="radius">The radius to add.</param>
        /// <returns></returns>
        public static WoWPoint CalculateNewPosition(WoWPoint from, float rotation, float radius)
        {
            return new WoWPoint(Math.Sin(rotation) * radius + from.X, Math.Cos(rotation) * radius + from.Y, from.Z);
        }

 

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.