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
Any part of the computer that you plug into the CPU like a phone, tablet, headphones etc. are called
gtnhenbr [62]

Answer:

usb

Explanation:

8 0
3 years ago
As in algebra, you can use brackets to override the order of operations Excel follows to perform formula calculations. True or f
sertanlavr [38]

Answer:

false

Explanation:

parasynthesis is used to change the order of priority.

6 0
3 years ago
What is search engine
koban [17]
Search engine is a software to help find you results over the internet.

Examples of search engines are: Google, Safari, Yahoo etc.
4 0
3 years ago
Read 2 more answers
Write a program that reads a file called 'test.txt' and prints out the contents on the screen after removing all spaces and newl
svp [43]

Answer:

I don't know  you should figure that out good luck

Explanation:

good luck

8 0
2 years ago
Why might you complete a 1040 instead of a <br> 1040ez
julia-pushkina [17]
Because compared to 1040EZ, 1040 way more more complex.


3 0
3 years ago
Read 2 more answers
Other questions:
  • Which of the following situations would not require knowledge of networking?
    6·1 answer
  • What is the main purpose of broadcasting via satellite? A. To enable signal reception at night B. To convert analog signals to d
    5·1 answer
  • Which column and row references are updated when you copy the formula: =F$5+12? Value 12 Column F Column F and row 5 Row 5
    8·1 answer
  • You are asked to design a system of FP numbers representation (with your own design choices), labeled Custom_FP_48, for which we
    8·1 answer
  • What year did buck tooth bob become famous
    11·2 answers
  • Which type of computer operating system would be best for a large corporation?
    7·2 answers
  • "which type of network connects smart devices or consumer electronics within a range of about 30 feet (10 meters) and without th
    7·1 answer
  • Hazel has taught herself a variety of computer languages. She enjoys using her knowledge to write the programs for applications
    7·2 answers
  • Select the correct text in the passage.
    12·1 answer
  • Profitability, consumer relations, and competition are involved in what kinds of concerns in the design process?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!