Hark, An Arc!

December 19, 2000, 01:00 AM —  ITworld — 

When you instanciate a Graphics2D object, you enable yourself to refer
to a bunch of interesting methods having to do with portions of
circles. A portion of a circle is called an arc, and the Graphics2D
object enables to you use arcs in three interesting ways:

* As open arcs, with no connections between their endpoints.
* As chorded arcs, with a chord (a straight line through what would
be the inside of the circle, were it complete) connecting the
arc's endpoints.
* As the basis for a pie (really a pie-slice, most of the time),
which is an arc with line segments connecting its endpoints to
the center of the circle that defines the arc.

Here's a little program illustrating the variations on the arc theme:

import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
class Arcs extends Frame {
public static void main(String arg[]) {
new Arcs();
}
Arcs() {
super("Arcs");
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e)
{ System.exit(0); } } );
setSize(350,330);
show();
}
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D)g;
Arc2D chord = getArcChord();
Arc2D open = getArcOpen();
Arc2D pie = getArcPie();
AffineTransform at = new AffineTransform();

// First row
at.setToTranslation(10.0,30.0);
g2.setTransform(at);
g2.draw(pie);
at.setToTranslation(120.0,30.0);
g2.setTransform(at);
g2.draw(open);
at.setToTranslation(230.0,30.0);
g2.setTransform(at);
g2.draw(chord);

// Second row
at.setToTranslation(10.0,60.0);
g2.setTransform(at);
pie.setAngleExtent(-135.0);
g2.draw(pie);
at.setToTranslation(120.0,60.0);
g2.setTransform(at);
open.setAngleExtent(-135.0);
g2.draw(open);
at.setToTranslation(230.0,60.0);
g2.setTransform(at);
chord.setAngleExtent(-135.0);
g2.draw(chord);

// Third row
at.setToTranslation(10.0,190.0);
g2.setTransform(at);
pie.setAngleStart(45.0);
pie.setAngleExtent(270.0);
g2.draw(pie);
at.setToTranslation(120.0,190.0);
g2.setTransform(at);
open.setAngleStart(45.0);
open.setAngleExtent(270.0);
g2.draw(open);
at.setToTranslation(230.0,190.0);
g2.setTransform(at);
chord.setAngleStart(45.0);
chord.setAngleExtent(270.0);
g2.draw(chord);
}
private Arc2D getArcPie() {
Arc2D.Float arc = new Arc2D.Float(
0.0f,0.0f,
100.0f,100.0f,
0.0f,45.0f,
Arc2D.PIE);
return(arc);
}
private Arc2D getArcChord() {
Arc2D.Float arc = new Arc2D.Float(
0.0f,0.0f,
100.0f,100.0f,
0.0f,45.0f,
Arc2D.CHORD);
return(arc);
}
private Arc2D getArcOpen() {
Arc2D.Float arc = new Arc2D.Float(
0.0f,0.0f,
100.0f,100.0f,
0.0f,45.0f,
Arc2D.OPEN);
return(arc);
}
}

» posted by ITworld staff

ITworld

I like it!
Post a comment
The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
Resources
White Paper

Symantec Backup Exec 12 and Backup Exec System Recovery 8 deliver industry leading Windows data protection and system recovery. Download this whitepaper to find out the top reasons to upgrade and how to get continuous data protection and complete system recovery.

Webcast

Data and system loss — from a hard drive failure, malicious attack, natural disaster, or simple human error — can happen anytime. Don’t leave your business vulnerable. Make sure you have a secure recovery strategy in place. Symantec's latest backup and system recovery technology can efficiently restore critical applications, individual emails and documents and even restore your entire system in minutes in the event of a loss.

White Paper

Businesses face a growing challenge to ensure that the IT environment is properly protected. Backup Exec 12 integrates with other applications in the Symantec family of products, to complement your current data protection strategy, keep your data securely backed up and make it recoverable when you need it most.

Free stuff

Enterprise 2.0 Implementation
By Aaron C. Newman, Jeremy Thomas
Published by McGraw-Hill
Learn more!

Deploying Cisco Wide Area Application Services
By Zach Seils, Joel Christner
Published by Cisco Press
Learn more!

Featured Sponsor

AISO founders envisioned a Web hosting company that was environmentally friendly. While the company employed energy-efficient innovations like solar panels, its infrastructure produced unacceptable power and cooling requirements. Find out how AISO leveraged AMD technology to overcome their challenge in this case study white paper.

In this whitepaper, Scalar explores the opportunity to change the landscape with respect to mission critical databases built around Oracle. Leveraging technologies such as Linux, high-end commodity processing power and Oracle RAC technology to architect, design, build and maintain database infrastructure that delivers maximum availability, reliability and performance at a fraction of traditional cost.

On a typical day, weather.com, the Web site for The Weather Channel in Atlanta, serves up between 15 million and 20 million page views. But in September 2004, when back-to-back hurricanes ransacked Florida, the peak traffic on one day more than tripled: over 70 million page views by more than 7 million unique visitors. Read the full success story now.

More Resources