Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6844063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:19:48+00:00 2026-05-27T00:19:48+00:00

I need a Cube that will draw in isometric projection, after that I need

  • 0

I need a Cube that will draw in isometric projection, after that I need it to turn around one of his axis (for example Z), this is my source, I can not understand how to use repaint() method to rotate the cube.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T00:19:49+00:00Added an answer on May 27, 2026 at 12:19 am

    I looked at “some” of your code (posted below), and yes, you need to use a Swing Timer for your game loop. Also, you’ll want to do drawing in your JPanel’s paintComponent method, not its paint method.

    Code:

    import javax.swing.*;
    import java.util.Timer;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.geom.Line2D;
    import java.awt.geom.Rectangle2D;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import java.lang.Object;
    import java.lang.Math;
    
    class Matrix {
       public double[][] times(double[][] A, double[][] B) {
          if (A[0].length == B.length) {
             int i, j, k;
             int m = A.length;
             int n = A[0].length;
             int q = B[0].length;
             double[][] C;
             double[] e;
             C = new double[m][q];
             e = new double[n];
             for (i = 0; i <= m - 1; i++) {
                // System.out.println();
                for (k = 0; k <= q - 1; k++) {
                   for (j = 0; j <= n - 1; j++) {
                      e[j] = A[i][j] * B[j][k];
                      C[i][k] = C[i][k] + e[j];
                   }
                   // System.out.print(C[i][k]+"                    ");
                }
             }
             // System.out.println(m+"@"+n+"@"+q);
             return C;
          } else {
             throw new RuntimeException("Illegal matrix dimensions.");
          }
       }
    
       // This method calculates the coordinates of Cube's dots
       public double[][] dots(double[] angle, String dot) {
          double[][] turnX = {
                { 1, 0, 0 },
                { 0, Math.cos(Math.toRadians(angle[0])),
                      (-1 * (Math.sin(Math.toRadians(angle[0])))) },
                { 0, Math.sin(Math.toRadians(angle[0])),
                      Math.cos(Math.toRadians(angle[0])) } };
          double[][] turnY = {
                { Math.cos(Math.toRadians(angle[1])), 0,
                      Math.sin(Math.toRadians(angle[1])) },
                { 0, 1, 0 },
                { (-1 * (Math.sin(Math.toRadians(angle[1])))), 0,
                      Math.cos(Math.toRadians(angle[1])) } };
          double[][] turnZ = {
                { Math.cos(Math.toRadians(angle[2])),
                      (-1 * (Math.sin(Math.toRadians(angle[2])))), 0 },
                { Math.sin(Math.toRadians(angle[2])),
                      Math.cos(Math.toRadians(angle[2])), 0 }, { 0, 0, 1 } };
          double[][][] dots = { { { 0 }, { 0 }, { 0 } }, { { 0 }, { 100 }, { 0 } },
                { { 100 }, { 100 }, { 0 } }, { { 100 }, { 0 }, { 0 } },
                { { 100 }, { 0 }, { 100 } }, { { 0 }, { 0 }, { 100 } },
                { { 0 }, { 100 }, { 100 } }, { { 100 }, { 100 }, { 100 } } };
    
          double[][] oMat = { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 0 } };
          double[][] am = { { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 } };
    
          Matrix mx = new Matrix();
    
          if (angle[0] != 0 || angle[1] != 0 || angle[2] != 0) {
             if (angle[0] != 0 && angle[1] != 0 && angle[2] != 0) {
                double[][] res = mx.times(turnX, turnY);
                am = mx.times(res, turnZ);
             } else if (angle[0] != 0 && angle[1] != 0 && angle[2] == 0) {
                am = mx.times(turnX, turnY);
             } else if (angle[0] != 0 && angle[1] == 0 && angle[2] != 0) {
                am = mx.times(turnX, turnZ);
             } else if (angle[0] != 0 && angle[1] == 0 && angle[2] == 0) {
                am = turnX;
             } else if (angle[0] == 0 && angle[1] != 0 && angle[2] != 0) {
                am = mx.times(turnY, turnZ);
             } else if (angle[0] == 0 && angle[1] != 0 && angle[2] == 0) {
                am = turnY;
             } else if (angle[0] == 0 && angle[1] == 0 && angle[2] != 0) {
                am = turnZ;
             }
    
             if (dot == "a") {
                double[][] A3d = mx.times(am, dots[0]);
                double[][] A = mx.times(oMat, A3d);
                return A;
             } else if (dot == "b") {
                double[][] B3d = mx.times(am, dots[1]);
                double[][] B = mx.times(oMat, B3d);
                return B;
             } else if (dot == "c") {
                double[][] C3d = mx.times(am, dots[2]);
                double[][] C = mx.times(oMat, C3d);
                return C;
             } else if (dot == "d") {
                double[][] D3d = mx.times(am, dots[3]);
                double[][] D = mx.times(oMat, D3d);
                return D;
             } else if (dot == "e") {
                double[][] E3d = mx.times(am, dots[4]);
                double[][] E = mx.times(oMat, E3d);
                return E;
             } else if (dot == "f") {
                double[][] F3d = mx.times(am, dots[5]);
                double[][] F = mx.times(oMat, F3d);
                return F;
             } else if (dot == "g") {
                double[][] G3d = mx.times(am, dots[6]);
                double[][] G = mx.times(oMat, G3d);
                return G;
             } else if (dot == "h") {
                double[][] H3d = mx.times(am, dots[7]);
                double[][] H = mx.times(oMat, H3d);
                return H;
             } else {
                throw new RuntimeException("Illegal dot name.");
             }
          } else {
             throw new RuntimeException("Zero angles.");
          }
    
       }
    }
    
    class Paint extends JPanel {
       public void paint(Graphics g) {
          // Angles { X , Y , Z}
          double[] angle = { 35.264, 45, 0 };
          Matrix mx = new Matrix();
          double[][] A = mx.dots(angle, "a");
          double[][] B = mx.dots(angle, "b");
          double[][] C = mx.dots(angle, "c");
          double[][] D = mx.dots(angle, "d");
          double[][] E = mx.dots(angle, "e");
          double[][] F = mx.dots(angle, "f");
          double[][] G = mx.dots(angle, "g");
          double[][] H = mx.dots(angle, "h");
    
          Dimension size = getSize();
          int w = (size.width) / 2;
          int t = (size.height) / 2;
          Graphics2D g2 = (Graphics2D) g;
          super.paint(g);
          for (int i = 0; i <= 360; i++) {
             angle[2] = i;
             g2.draw(new Line2D.Double((w + A[0][0]), (t + (-1 * (A[1][0]))),
                   (w + B[0][0]), (t + (-1 * (B[1][0])))));
             g2.draw(new Line2D.Double((w + B[0][0]), (t + (-1 * (B[1][0]))),
                   (w + C[0][0]), (t + (-1 * (C[1][0])))));
             g2.draw(new Line2D.Double((w + C[0][0]), (t + (-1 * (C[1][0]))),
                   (w + D[0][0]), (t + (-1 * (D[1][0])))));
             g2.draw(new Line2D.Double((w + D[0][0]), (t + (-1 * (D[1][0]))),
                   (w + A[0][0]), (t + (-1 * (A[1][0])))));
             g2.draw(new Line2D.Double((w + A[0][0]), (t + (-1 * (A[1][0]))),
                   (w + F[0][0]), (t + (-1 * (F[1][0])))));
             g2.draw(new Line2D.Double((w + B[0][0]), (t + (-1 * (B[1][0]))),
                   (w + G[0][0]), (t + (-1 * (G[1][0])))));
             g2.draw(new Line2D.Double((w + C[0][0]), (t + (-1 * (C[1][0]))),
                   (w + H[0][0]), (t + (-1 * (H[1][0])))));
             g2.draw(new Line2D.Double((w + D[0][0]), (t + (-1 * (D[1][0]))),
                   (w + E[0][0]), (t + (-1 * (E[1][0])))));
             g2.draw(new Line2D.Double((w + E[0][0]), (t + (-1 * (E[1][0]))),
                   (w + F[0][0]), (t + (-1 * (F[1][0])))));
             g2.draw(new Line2D.Double((w + F[0][0]), (t + (-1 * (F[1][0]))),
                   (w + G[0][0]), (t + (-1 * (G[1][0])))));
             g2.draw(new Line2D.Double((w + G[0][0]), (t + (-1 * (G[1][0]))),
                   (w + H[0][0]), (t + (-1 * (H[1][0])))));
             g2.draw(new Line2D.Double((w + H[0][0]), (t + (-1 * (H[1][0]))),
                   (w + E[0][0]), (t + (-1 * (E[1][0])))));
             // Timer timer = new Timer(100);
             // timer.start();
             try {
                Thread.sleep(10);
             } catch (InterruptedException ie) {
             }
             this.repaint();
             // setFocusable(true);
    
          }
       }
    }
    
    public class Cube {
    
       public static void main(String[] args) {
          JFrame frame = new JFrame("Malakhovskyi BS11-01");
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.add(new Paint());
          frame.pack();
          frame.setSize(640, 480);
          frame.setLocationRelativeTo(null);
          frame.setVisible(true);
    
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to display content from an OLAP cube in Sharepoint. This could be
I've created 3 Java classes. one that has a glsurfaceview object and this calls
I am told that for a simple cube I need 36 vertices when I
I need to draw a gridded image using opengl. I've read that images created
I've a cube with around 30 dimensions and 10 measure groups. I need to
I need to draw a texture on a square polygon, not a cube, i
I need to create a 3D model of a cube with a circular hole
Need a function that takes a character as a parameter and returns true if
Need to an expression that returns only things with an I followed by either
Need a function like: function isGoogleURL(url) { ... } that returns true iff URL

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.