Objekt um Fixpunkt drehen

01/27/2012 22:26 vwap#1
Hey, ich habe eine Frage, welches keine direkte Programmiersprache betrifft, sondern welche auf alle Anwendbar ist.
Ich habe ein Objekt.
Dies ist ein 2D-Vektor. (Somit X und Y Achse).
Nun habe ich einen Fixpunkt (auch ein 2D-Vektor).
Wie kann ich nun das Objekt in einem bestimmten Abstand mit einer bestimmten Geschwindigkeit um den Fixpunkt drehen lassen?
Ich bräuchte nur die Formel.
01/28/2012 09:34 jacky919#2
Gegeben sind y, x und a:
y' = sin(a + atan(y/x)) * sqrt(x^2 + y^2)
x' = cos(a + atan(y/x)) * sqrt(x^2 + y^2)

x' und y' sind die neuen Postionen von x und y, ausgegangen davon, dass der Punkt um den gedreht wird (0|0) ist.

Ich weiß nicht, ob es funktionieren wird. Ich gehe aber davon aus :)
01/28/2012 11:06 vwap#3
Genau so hab ich's schon versucht, klappt aber nicht.
Habs jetzt aber selbst gelöst ;)
01/28/2012 12:02 .Infinite#4
Wie? Würde mich auch interessieren!
01/28/2012 21:41 vwap#5
Code:
 proton.position.X = graphics.PreferredBackBufferWidth / 2;
                proton.position.Y = graphics.PreferredBackBufferHeight / 2;
// ^ position, um die sich das objekt drehen soll (bildschirmmitte)

                proton.angle += 0f; // Drehgeschwindigkeit
                proton.angle %= MathHelper.TwoPi;

                if (proton.distance > 40f) proton.distance -= (float) rand.Next(0, 5) / 10; // proton.distance ist der abstand vom rotierungspunkt
                
                var protonPos = new Vector3(proton.position.X, proton.position.Y, 0);
                var origin = new Vector2(proton.texture.Width, proton.texture.Height) / 2f;

                Matrix mat = Matrix.CreateTranslation(new Vector3(-origin, 0)) * Matrix.CreateTranslation(new Vector3(proton.distance, 0, 0)) * Matrix.CreateRotationZ(proton.angle) * Matrix.CreateTranslation(protonPos);

                proton.position = Vector2.Transform(Vector2.Zero, mat);
"proton" ist ne eigene Klasse:
Code:
 public class Proton : Species
    {

        public float health;
        public float distance;
        public float angle;
        public float speed;

    }
Leitet sich von Species ab:
Code:
public class Species
    {

        public Texture2D texture;
        public int id;
        public Vector2 position;

    }
01/28/2012 22:07 jacky919#6
ok, ich wusste natürlich nicht, dass dir Matrizen zur Verfügung stehen...