?
Solved

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

Posted on 2003-03-13
5
Medium Priority
?
596 Views
Last Modified: 2012-06-21
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
Comment
Question by:Kiwib
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 35

Expert Comment

by:girionis
ID: 8128867
 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
 

Accepted Solution

by:
JackNCalvin earned 180 total points
ID: 8129021
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 Comment

by:Kiwib
ID: 8133037
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 Comment

by:Kiwib
ID: 8133048
Thanks, Jack
0
 
LVL 4

Expert Comment

by:delphi3
ID: 8137022
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);
    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) {
        System.exit(0);
      }
    });

    f.getContentPane().add(imagePanel, BorderLayout.CENTER);
    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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month11 days, 11 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question