• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 606
  • Last Modified:

How can I use Graphics2D to draw a tetrahedron that looks 3d

Is it possible to use Graphics2D to draw a tetrahedron that looks 3d?
If so, what are the basic methods?
I have not been able to find anything in the API, etc.
1 Solution
 I don't think you can do it with java2d. A tetrahedron is essentially a pyramid (three sides that unite at the top and the bottom side) in 3D. Maybe this would help though:


You are right, you won't find anything in the 2D API.  The 3D API doesn't have a specific tetrahedron specification either.  However, if you really want to use the 2D graphic Api, you could define your own Tetrahedron drawing class.  

Here is a suggestion:

- You would need a function to draw the base. This is very easy, you just need three points and you can draw a triangle.  

- You would then need to define/set a top point.  If you have the base vertices it is easy to draw lines from each of the base vertice points to the top.  This would create a 3d like tetrahedron.

-Filling it would be a little more difficult.  You would need to calculate the vertices for the 4 separate sides and then drawfill the polygon.

-It would probably be cool, if you could click and drag the top point, and have the tetrahedron change as you drag.  

What kind of project are you working on anyway?

I hope this helps!

KiwibAuthor Commented:
Thanks very much.
It is just an assignment for my Client-Server class at Montgomery College, Maryland.
I guess I will close this question out.
KiwibAuthor Commented:
Thanks, Jack
Hi Kiwib,
I  know that this is after the fact, your were well satisfied with the answer from Jack.  However I thought this looked pretty neat.

This is a rotating gif from the address shown below.
I suspect that you needed to draw your own.

But is there a need to reinvent the wheel?


package getimage;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

// internet location of Tetrahedron.gif
// http://www.eas.purdue.edu/~dano/personal/anim/page_07.htm

public class GettingImage
    extends JApplet {

  static String imageFile = "imageFile/" + "Tetrahedron.gif";
  public void init() {
    Image image = getImage(getCodeBase(), imageFile);
    ImagePanel imagePanel = new ImagePanel(image);
    getContentPane().add(imagePanel, BorderLayout.CENTER);

  public static void main(String[] args) {
    Image image = Toolkit.getDefaultToolkit().getImage(imageFile);
    ImagePanel imagePanel = new ImagePanel(image);

    JFrame f = new JFrame("GetImageFromFile");
    f.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {

    f.getContentPane().add(imagePanel, BorderLayout.CENTER);
    f.setSize(new Dimension(300, 300));

class ImagePanel
    extends JPanel {
  Image image;

  public ImagePanel(Image image) {
    this.image = image;

  public void paintComponent(Graphics g) {
    super.paintComponent(g); //paint background

    //Draw image at this natural size first.
    g.drawImage(image, 50, 50, this);

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now