Zykloide zeichnen in JAVA

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • Zykloide zeichnen in JAVA

    Hallo,

    ich brauch dringend Hilfe. Undzwar möchte ich ein Javaprogramm coden, dass eine Zykloide zeichnen kann. (de.wikipedia.org/wiki/Zykloide) Das Zeichnen ansich geht schonmal allerdings ist immer ein langgezogner strich auf der "x-achse" den ich nicht wegbekomme. des weiteren möchte ich das animieren das der graph quasi stück für stück entsteht (aber nicht als javascript). wäre nett wenn mir wer helfen kann.
    VIelen Dank schonmal

    Quellcode

    1. import java.awt.*;
    2. import javax.swing.JPanel;
    3. public class Cycloid extends JPanel {
    4. int r1;
    5. int r2;
    6. Polygon p;
    7. Point pu;
    8. int centerx = 50;
    9. int centery= 100;
    10. final int numPoints = 20000;
    11. public Cycloid (int inner , int outer) {
    12. r1 = inner;
    13. r2 = outer;
    14. p = new Polygon ( );
    15. for (int t = 0; t < numPoints; t++) {
    16. double theta = 2.0 * Math.PI * t / numPoints;
    17. double x = (r1 + r2) * Math.cos (theta) + r2 * Math.cos (theta * r1 / r2);
    18. double y = (r1 + r2) * Math.sin (theta) + r2 * Math.sin (theta * r1 / r2);
    19. p.addPoint ( centerx + (int)x, centery +(int) y);
    20. }
    21. }
    22. public Cycloid (int rad) {
    23. r1 = rad;
    24. p = new Polygon ();
    25. for (double t = 0; t < numPoints;) {
    26. double x = (r1) * (t - Math.sin (t));
    27. double y = (r1) *(1- Math.cos (t));
    28. p.addPoint ( centerx + (int)x, centery -(int) y);
    29. t=t+0.01;
    30. }
    31. }
    32. public void paintComponent (Graphics g) {
    33. super.paintComponent (g);
    34. g.setColor (Color.blue);
    35. g.drawPolygon (p);
    36. }
    37. }
    Alles anzeigen



    und hier die testklasse

    Quellcode

    1. import javax.swing.*;
    2. import java.awt.*;
    3. public class testCycloid extends JFrame{
    4. public testCycloid () {
    5. getContentPane ().setLayout (new GridLayout ());
    6. getContentPane ().add (new Cycloid (10));
    7. };
    8. public static void main(String[ ] args) {
    9. testCycloid pict = new testCycloid();
    10. pict.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
    11. pict.setSize (600, 300);
    12. pict.setVisible (true);
    13. }
    14. }
    Alles anzeigen

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von JohnSmith ()