go to previous page   go to home page   go to next page highlighting

Answer:

Sure


Irregular Polygon

Polygon Snake: Hisss...

Here is a program that draws an irregular green polygon (and a few other shapes.) The figure was drawn on graph paper, then the vertices were read off and put into an array of double:

double[] snake =  { 30,150, 150,60, 240,90, 360,30, 450,90, 480,60, 510,90,
                    480,120, 450,105, 360,60, 240,120, 150,78  };

Polygon polygon = new Polygon( snake );
polygon.setFill( Color.GREENYELLOW ); 

The polygon is concave. This means that for some pairs of points inside the polygon, a line connecting the points will pass outside the polygon. A regular polygon is convex, which means that any two points can be connected with a line that stays entirely within the polygon.


import javafx.application.*;
import javafx.stage.*;
import javafx.scene.Scene;  
import javafx.scene.shape.*;
import javafx.scene.paint.*;
import javafx.scene.layout.*; 
import java.util.Scanner;

public class PolygonSnake extends Application
{
 
  public void start( Stage primaryStage )
  {
    double sceneWidth = 550.0, sceneHeight = 200.0;
     
    // array of vertices x,y, x,y, x,y
 
    double[] snake =  { 30,150, 150,60, 240,90, 360,30, 450,90, 480,60, 510,90,
                        480,120, 450,105, 360,60, 240,120, 150,78  };
    
    Polygon polygon = new Polygon( snake );
    polygon.setFill( Color.GREENYELLOW );
    
    Ellipse eye = new Ellipse( 480, 83, 5, 3 );
    eye.setFill( Color.BLACK );
    Line line1 = new Line( 490, 105, 510, 115 );
    line1.setStroke( Color.RED ); line1.setStrokeWidth( 1.5 );
    Line line2 = new Line( 510, 115, 525, 110 );
    line2.setStroke( Color.RED ); line2.setStrokeWidth( 1.5 );
    Line line3 = new Line( 510, 115, 520, 130 );
    line3.setStroke( Color.RED ); line3.setStrokeWidth( 1.5 );
         
    Pane pane = new Pane( line1, line2, line3, polygon, eye );
    Scene scene = new Scene( pane, sceneWidth, sceneHeight, Color.HONEYDEW);
    
    primaryStage.setTitle("Irregular Polygon Demo");
    primaryStage.setScene( scene );
    primaryStage.show();
  }
}

QUESTION 10:

If you create a regular polygon with very many sides, what does the resulting figure resemble?


go to previous page   go to home page   go to next page