コード例 #1
0
        public Transform2D orthonormalized()
        {
            Transform2D on = this;

            Vector2 onX = on.x;
            Vector2 onY = on.y;

            onX.normalize();
            onY = onY - onX * (onX.dot(onY));
            onY.normalize();

            on.x = onX;
            on.y = onY;

            return(on);
        }
コード例 #2
0
        public Transform2D interpolate_with(Transform2D m, float c)
        {
            float r1 = Rotation;
            float r2 = m.Rotation;

            Vector2 s1 = Scale;
            Vector2 s2 = m.Scale;

            // Slerp rotation
            Vector2 v1 = new Vector2(Mathf.cos(r1), Mathf.sin(r1));
            Vector2 v2 = new Vector2(Mathf.cos(r2), Mathf.sin(r2));

            float dot = v1.dot(v2);

            // Clamp dot to [-1, 1]
            dot = (dot < -1.0f) ? -1.0f : ((dot > 1.0f) ? 1.0f : dot);

            Vector2 v = new Vector2();

            if (dot > 0.9995f)
            {
                // Linearly interpolate to avoid numerical precision issues
                v = v1.linear_interpolate(v2, c).normalized();
            }
            else
            {
                float   angle = c * Mathf.acos(dot);
                Vector2 v3    = (v2 - v1 * dot).normalized();
                v = v1 * Mathf.cos(angle) + v3 * Mathf.sin(angle);
            }

            // Extract parameters
            Vector2 p1 = Origin;
            Vector2 p2 = m.Origin;

            // Construct matrix
            Transform2D res   = new Transform2D(Mathf.atan2(v.y, v.x), p1.linear_interpolate(p2, c));
            Vector2     scale = s1.linear_interpolate(s2, c);

            res.x *= scale;
            res.y *= scale;

            return(res);
        }
コード例 #3
0
 public Vector2 basis_xform_inv(Vector2 v)
 {
     return(new Vector2(x.dot(v), y.dot(v)));
 }