Creating 3D Objects


 

Tutorial Home

Helpful Videos

 Rect

The following code will create a view of a Rect.

public static void main(String[] args) 
	{
		Win2D win = new Win2D("Tutorial",10,20,400,300);
		Rect myRect = new Rect(0,0,6,4);
		win.add(myRect);
		
		win.add(new Axes());

	}

This produces the view: Cube

Note that the center of the rectangle has been placed at the origin and that its width is 6 and height is 4 as specified when the rectangle was created.

Oval The following code with create a Oval centered at the origin.
	
 public static void main(String[] args) 
	{
		Win2D win = new Win2D("Tutorial",10,20,400,300);
		Oval flatBall = new Oval(0,0,10,2);
		win.add(flatBall);
		
		win.add(new Axes());

	}

The ball has be squashed to 10 wide and 2 high. The resulting view is: Oval

 

Arc

The following code creates a pie-shaped arc whose center is at [0,2]. The diameter of the circle that this arc is drawn from is 10 (radius 5). Note that the arc starts at 45 degrees counter-clockwise from the X axis and extends for 90 degrees.

    	
 public static void main(String[] args) 
	{
		Win2D win = new Win2D("Tutorial",10,20,400,300);
		Arc myArc = new Arc(0,2,10,10,45,90);
		win.add(myArc);
		
		win.add(new Axes());

	}
The resulting view is: Cone
Line

The following code creates and draws a Line that extends from [-4,-1] to [3,4]. Note also that the line width has been changed to make it wider than normal.

    	
public static void main(String[] args) 
	{
		Win2D win = new Win2D("Tutorial",10,20,400,300);
		Line myLine = new Line(-4,-1,3,4);
		myLine.setLineWidth(0.2);
		win.add(myLine);
		
		win.add(new Axes());

	}
The resulting view is: Cylinder
Text

The Text object displays some text. Notice that the left edge of the text's baseline starts at the point [-1,1].

	
public static void main(String[] args) 
	{
		Win2D win = new Win2D("Tutorial",10,20,400,300);
		Text myText = new Text(-1,1,"Some cool text");
		win.add(myText);
		
		win.add(new Axes());

	}
The view that this produces is: Floor