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

# 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.
Thanks.
Kiwib
0
Kiwib
1 Solution

Commented:
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:

http://www.apl.jhu.edu/~hall/java/Java2D-Tutorial.html
0

Commented:
Kiwib:

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!

-Jack-
0

Author 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.
0

Author Commented:
Thanks, Jack
0

Commented:
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?

Delphi3

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);
}

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

JFrame f = new JFrame("GetImageFromFile");
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});

f.setSize(new Dimension(300, 300));
f.setVisible(true);
}
}

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);
}
}
0

## Featured Post

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