Rotate Vector : Vector « Development Class « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Date Time
8.Design Patterns
9.Development Class
10.Event
11.File Stream
12.Generics
13.GUI Windows Form
14.Internationalization I18N
15.Language Basics
16.LINQ
17.Network
18.Office
19.Reflection
20.Regular Expressions
21.Security
22.Services Event
23.Thread
24.Web Services
25.Windows
26.Windows Presentation Foundation
27.XML
28.XML LINQ
C# / C Sharp » Development Class » VectorScreenshots 
Rotate Vector
        
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;

namespace InfoStrat.VE.Utilities
{
    public static class MathHelper
    {
        public static Vector RotateVector(Vector v, double angle)
        {
            double len = v.Length;

            if (len == 0)
                return v;

            double refAngle = Get2DAngle(v, new Vector(10));

            double dx = len * Math.Cos((refAngle + angle* Math.PI / 180.0);
            double dy = -len * Math.Sin((refAngle + angle* Math.PI / 180.0);

            return new Vector(dx, dy);
        }

        public static double Get2DAngle(Vector a, Vector b)
        {
            double cosine = (a.X * b.X + a.Y * b.Y(a.Length * b.Length);

            if (cosine > 1)
                cosine = 1;
            else if (cosine < -1)
                cosine = -1;

            if ((a.X * b.Y - a.Y * b.X0)
                return -Math.Acos(cosine180.0 / Math.PI;
            else
                return Math.Acos(cosine180.0 / Math.PI;
        }

        public static double MapValue(double value, double fromMin, double fromMax, double toMin, double toMax)
        {
            //Normalize
            double ret = (value - fromMin(fromMax - fromMin);
            //Resize and translate
            return ret * (toMax - toMin+ toMin;
        }

        public static double Clamp(double value, double min, double max)
        {
            double actualMin = Math.Min(min, max);
            double actualMax = Math.Max(min, max);
            return Math.Min(actualMax, Math.Max(actualMin, value));
        }
    }
}

   
    
    
    
    
    
    
    
  
Related examples in the same category
1.Vector class
2.Truncate Vector2
3.Perpendicular Vector2
4.Vector2D struct
5.Gets the perpendicular vector to a specified vector
6.Compares Vector3 values for equality
7.Finds the cross product of the 2 vectors created by the 3 vertices.
8.Remap a value specified relative to a pair of bounding values to the corresponding value relative to another pair of bounds.
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.