Wer kann mir helfen bei Koordinatentransformation ?



  • Hi!
    Wie ich habe eine Kompassnadel erstellt mit 8 punkten nun will ich sie grafisch drehen wer kann mir die formel erkären bzw gibt es eine funktion in Bc++ dafür?
    danke für die Hilfe!!!

    :xmas2:



  • Sinus und Cosinus 😉



  • jo jo aber klappt leider nicht 🙄

    grad = (grad *(M_PI/180))*2;
    
    px1=(px1*cos(grad)+py1*sin(grad));
      py1=(py1*cos(grad)-px1*sin(grad));
    


  • Du solltest das besser nicht "vor Ort" ändern - mit der ersten Anweisung zerlegst du dir nämlich die Ausgangsdaten für die zweite:

    px2=(px1*cos(grad)+py1*sin(grad));
    py2=(py1*cos(grad)-px1*sin(grad));
    

    Außerdem solltest du darauf achten, wo der Nullpunkt deines Koordinatensystems liegt und um welchen Punkt du drehen willst.



  • float Rad = 1.74532925199433E-02;
    float Grad = 45;
    float coswinkel = cos(Grad*Rad);
    float sinwinkel = sin(Grad*Rad);
    float mx=12; //Drehmittelpunkt X
    float my=12; //Drehmittelpunkt Y
    
    float X,Y;
    X=coswinkel * points[0].x + sinwinkel * points[0].y + mx * (1 - coswinkel) - sinwinkel * my;
    Y=coswinkel * points[0].y - sinwinkel * points[0].x + my * (1 - coswinkel) + sinwinkel * mx;
    


  • danke probiere ich gleich mal aus 👍 👍



  • ne klappt irfenwie nicht ist immer noch ein versatz drin was ist RAD Radius bogenmaß oder wie? 😕



  • Hab ich jetzt mal so probiert :

    double Rad = 1.74532925199433E-02;
    float coswinkel = cos(CS2->Value*Rad);
    float sinwinkel = sin(CS2->Value*Rad);
    px1=coswinkel * px1 + sinwinkel * py1 + px0 * (1 - coswinkel) - sinwinkel * py0;
    py1=coswinkel * py1 - sinwinkel * px1 + py0 * (1 - coswinkel) + sinwinkel * px0;
    
    px2=coswinkel * px2 + sinwinkel * py2 + px0 * (1 - coswinkel) - sinwinkel * py0;
    py2=coswinkel * py2 - sinwinkel * px2 + py0 * (1 - coswinkel) + sinwinkel * px0;
    
    px1=coswinkel * px3 + sinwinkel * py3 + px0 * (1 - coswinkel) - sinwinkel * py0;
    py1=coswinkel * py3 - sinwinkel * px3 + py0 * (1 - coswinkel) + sinwinkel * px0;
    
    px1=coswinkel * px4 + sinwinkel * py4 + px0 * (1 - coswinkel) - sinwinkel * py0;
    py1=coswinkel * py4 - sinwinkel * px4 + py0 * (1 - coswinkel) + sinwinkel * px0;
    

    aber wie gesagt klappt nicht so ganz



  • is alles ok hab schon raus das fehlt:

    double x = coswinkel * points[1].x + sinwinkel * points[1].y + px0 * (1- coswinkel) - sinwinkel * py0;
      double y= coswinkel * points[1].y - sinwinkel * points[1].x + py0 * (1- coswinkel) + sinwinkel * px0;
       points[1].x = x;
       points[1].y = y;
    

Anmelden zum Antworten