1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
REY [17]
3 years ago
12

Polygon transform (25 points). Write a library of static methods that performs various geometric transforms on polygons. Mathema

tically, a polygon is defined by its sequence of vertices (x0, y 0), (x 1, y 1), (x 2, y 2), …. In Java, we will represent a polygon by storing the x– and y-coordinates of the vertices in two parallel arrays x[] and y[].
Computers and Technology
1 answer:
kari74 [83]3 years ago
6 0

Answer:

import java.lang.*;               //for using Math.cos() and Math.sin() and Math.toRadians() funcitons in rotate method

public class PolygonTransform

{

  public static double[] copy(double[] array)

  {

      double[] newArray = new double[array.length];

      for(int i=0;i<array.length;i++)

      {

          newArray[i] = array[i];

          return newArray;

      }

  }

  public static void scale(double[]x,double[]y,double alpha)

  {

      for(int i=0;i<x.length;i++)

      {

          x[i] *= alpha;

          y[i] *= alpha;

      }

  }

  public static void translate(double[]x,double[]y,double dx,double dy)

  {

      for(int i=0;i<x.length;i++)

      {

          x[i] += dx;

          y[i] += dy;

      }

  }

  public static void rotate(double[] x, double[]y,double theta)

  {

      double rad = Math.toRadians(theta);

      double temp;

      for(int i=0;i<x.length;i++)

      {

          temp = x[i];                           //For storing temporarily the previous value of x before changing so tha it can be used in changing y

          x[i] = x[i]*Math.cos(rad) - y[i]*Math.sin(rad);

          y[i] = y[i]*Math.cos(rad) + temp*Math.sin(rad);  

      }

  }

  public static void main(String args[])

  {

      //This is just implementing you testcase discripted.

      double[]x = new double[4];

      double[]y = new double[4];

      StdDraw.setScale(-5.0, +5.0);

      x = { 0, 1, 1, 0 };

      y = { 0, 0, 2, 1 };

      double alpha = 2.0;

      StdDraw.setPenColor(StdDraw.RED);

      StdDraw.polygon(x, y);

      scale(x, y, alpha);

      StdDraw.setPenColor(StdDraw.BLUE);

      StdDraw.polygon(x, y);

      // Translates polygon by (2, 1).

      StdDraw.setScale(-5.0, +5.0);

      x = { 0, 1, 1, 0 };

      y = { 0, 0, 2, 1 };

      double dx = 2.0, dy = 1.0;

      StdDraw.setPenColor(StdDraw.RED);

      StdDraw.polygon(x, y);

      translate(x, y, dx, dy);

      StdDraw.setPenColor(StdDraw.BLUE);

      StdDraw.polygon(x, y);

      // Rotates polygon 45 degrees.

      StdDraw.setScale(-5.0, +5.0);

      x = { 0, 1, 1, 0 };

      y = { 0, 0, 2, 1 };

      double theta = 45.0;

      StdDraw.setPenColor(StdDraw.RED);

      StdDraw.polygon(x, y);

      rotate(x, y, theta);

      StdDraw.setPenColor(StdDraw.BLUE);

      StdDraw.polygon(x, y);

  }

}

Explanation:

You might be interested in
Selecting the Tiled windows arrangement option places the windows in a(n) _______ pattern on the screen.
Archy [21]

Answer:

Selecting the Tiled windows arrangement option places the windows in a(n) Grid pattern on the screen.

Explanation:

3 0
2 years ago
The frequency of a sine wave is defined as:
LekaFEV [45]

Answer:

a.the number of cycles per second

Explanation:

The frequency of a sine wave is defined as the number of cycles per second.

Frequency is the inverse of the time period. The frequency of a sine wave is given by 1/TimePeriod . It is generally expressed in units of Hertz(Hz) or sec^-1. Larger the time period, lower will be the frequency and vice versa. So for higher frequency waves we need to ensure that the time period is small.

7 0
3 years ago
Formatting commands can be used to add number formats? True of false
Aleks04 [339]

Answer:

false

Explanation:

3 0
3 years ago
How do you feel about the Furry Fandom?
gtnhenbr [62]
When you don’t know who or what that is, and I pop- lol I need a life
8 0
3 years ago
CAN SOMEONE DO OR LOOK UP THE PIE CHART FOR THIS ANSWER PLS AND I WILL MARK YOU BRAINLIEST BUT PLSSS HELP MEEEE!!!
beks73 [17]

Answer:

I highly recommened you use ggl charts.

Explanation:

It's free. ALL YOU NEED IS AN GGL ACCOUNT. You can also choose many types of graph you want.

4 0
3 years ago
Other questions:
  • Erick, who is taking an online course, sent an e-mail to his
    14·2 answers
  • Which are the best examples of costs that should be considered when creating a project budget?
    11·1 answer
  • Write a java program that accepts the ingredients for a recipe in cups and converts to ounces
    10·1 answer
  • The engineering firm you work for is submitting a proposal to create an amphitheater at a state park. Proposals must be submitte
    15·1 answer
  • To ensure that comments identify the initials of the person making changes, you would need to _____.
    5·2 answers
  • PLS HELP ME!! WILL GIVE BRAINLIEST
    7·2 answers
  • HELP PLEASE
    7·1 answer
  • Which line of code in this program is MOST likely to result in an error
    15·2 answers
  • write ms-dos command to list all the files and folders of EIGHT sub directory of C: drive in ascending order according to file n
    5·1 answer
  • How does Accenture help companies harness the power of data to achieve optimal business outcomes?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!