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
in Java programming Design a program that will ask the user to enter the number of regular working hours, the regular hourly pay
iren2701 [21]

Answer:

In Java:

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

 int regularhour,overtimehour;

 float regularpay,overtimepay;

 Scanner input = new Scanner(System.in);

 

 System.out.print("Regular Hour: ");

 regularhour = input.nextInt();

 

 System.out.print("Overtime Hour: ");

 overtimehour = input.nextInt();

 

 System.out.print("Regular Pay: ");

 regularpay = input.nextFloat();

 

 System.out.print("Overtime Pay: ");

 overtimepay = input.nextFloat();

 

 float regulargross = regularhour * regularpay;

 float overtimegross = overtimehour * overtimepay;

 float totalgross = regulargross + overtimegross;

 

 System.out.println("Regular Gross Pay: "+regulargross);

 System.out.println("Overtime Gross Pay: "+overtimegross);

 System.out.println("Total Gross Pay: "+totalgross);

 

}

}

Explanation:

This line declares regularhour and overtimehour as integer

 int regularhour,overtimehour;

This line declares regularpay and overtimepay as float

 float regularpay,overtimepay;

 Scanner input = new Scanner(System.in);

 

This prompts the user for regular hour

 System.out.print("Regular Hour: ");

This gets the regular hour

 regularhour = input.nextInt();

 

This prompts the user for overtime hour

 System.out.print("Overtime Hour: ");

This gets the overtime hour

 overtimehour = input.nextInt();

 

This prompts the user for regular pay

 System.out.print("Regular Pay: ");

This gets the regular pay

 regularpay = input.nextFloat();

 

This prompts the user for overtime pay

 System.out.print("Overtime Pay: ");

This gets the overtime pay

 overtimepay = input.nextFloat();

 

This calculates the regular gross pay

 float regulargross = regularhour * regularpay;

This calculates the overtime gross pay

 float overtimegross = overtimehour * overtimepay;

This calculates the total gross pay

 float totalgross = regulargross + overtimegross;

 

This prints the regular gross pay

 System.out.println("Regular Gross Pay: "+regulargross);

This prints the overtime gross pay

 System.out.println("Overtime Gross Pay: "+overtimegross);

This prints the total gross pay

 System.out.println("Total Gross Pay: "+totalgross);

8 0
2 years ago
According to your textbook, the three major criteria against which to test documents that you locate on the Internet are authors
pantera1 [17]

Answer:

The following statement is False.

Explanation:

Because asper textbook there are only one main criteria against the test documents that find on the internet i.e., authorship. So, that's why the following given statement is false. The graphic and the interactivity depends on the quality of the document this options do not come under the criteria to test the document.

6 0
3 years ago
Given the string variable address, write an expression that returns the position of the first occurrence of the string avenue in
Delicious77 [7]
It depends on a language you code. I think this could be either C++ or Java. I know answer for both of them.
For C++:  <span>address.find("Avenue")
For Java: </span><span>address.indexOf("Avenue")</span>
4 0
2 years ago
g Suppose the vertex data is stored in an array named verts and each vertex uses a list to store the coordinates. Write the code
kodGreya [7K]

Answer:

function createAndFillBufferObject(gl, data) {

 var buffer_id;

 // Create a buffer object

 buffer_id = gl.createBuffer();

 if (!buffer_id) {

   out.displayError('Failed to create the buffer object for ' + model_name);

   return null;

 }

 // Make the buffer object the active buffer.

 gl.bindBuffer(gl.ARRAY_BUFFER, buffer_id);

 // Upload the data for this buffer object to the GPU.

 gl.bufferData(gl.ARRAY_BUFFER, data, gl.STATIC_DRAW);

 return buffer_id;

}

3 0
3 years ago
a) What are the 'interrupts' in a computer system? Describe the approaches to deal with multiple interrupts in a system.b) Analy
Fynjy0 [20]

Answer:

a)

An interrupt is a signal sent to the processor which indicates an event that needs immediate attention.

  • Interrupts are usually sent to CPU by external or I/O devices.
  • This notifies the processor to a high-priority process that requires the current process to be disrupted.
  • Interrupts requests the processor to stop its ongoing operations and run appropriate part of OS.
  • If the request is acknowledged, the processor may respond by halting its current operation, saving its state. Processor then executes a function called an interrupt handler to handle the event that needs attention.
  • This interrupt is temporary, and processor continues normal activities after the interrupt operator stops, unless the interrupt shows a fatal error.
  • The CPU must inform the device that its interrupt request is acknowledged so that it stops sending interrupt signals.
  • Interrupts are usually used for multitasking purposes in real time computers.
  • There are two basic types of interrupts: hardware and software interrupts.
  • A hardware interrupt requests are generated by hardware devices, to indicate that it needs attention from the operating system.
  • Software interrupts are either requested by programs when they want  some service from the operating system or these interrupts are generated by processor itself on executing particular instructions or when certain requirements are met.

Approaches to deal with multiple interrupts:

There are two approaches to handle multiple interrupts.

  1. One approach is to disable interrupts while an interrupt is being processed. A disabled interrupt means that processor will ignore that interrupt request. If during this phase an interrupt happens, it usually remains pending and will be reviewed by the processor after the interrupts has been enabled by the processor. So, when a program is being executed and an interrupt happens, interrupts are disabled immediately.Upon completion of the interrupt handler procedure, interrupts are allowed before the user program resumes, and the processor checks if other interrupts have occurred. This is a simple technique which deals with the interrupts sequentially. But it does not deal with priority requirements.
  2. Second approach is to define interrupt priorities to enable a higher priority interrupt to cause disruption of a lower-priority interrupt handler. For example take a system with 3 I/O devices: printer, disk and communication line with priorities 3,5, and 7. Lets say when a program starts a printer interrupt happens. The execution continues at printer ISR. At some time interval communication interrupt happens whilst this ISR is still executing. Due to the higher priority of the communication line than the printer, the interrupt is accepted and printer routine is interrupted. Its state is placed on stack and now execution resumes at communication line ISR. Now at some time interval the disk interrupt happens while communication routine is still executing. As the priority of disk interrupt is lower so this is held and communication isr execute completely. Suppose communication ISR finishes, then the previous state is resumed which is printer's ISR execution. But as the disk has higher priority than printer, the processor continues execution in disk ISR. After the completion of disk routine execution, the printer ISR is resumed. After the printer ISR execution is completed the control goes back to the user program.

b) Benefits of using multiple bus architecture compared to single bus architecture are as follows:

  • In a multiple bus architecture each pathway is tailored to deal with a specific type of information. This enhances performance as compared to single bus architecture which is used by simple computers to transfer data onto single bus. Performance enhancement is an important reason for having multiple buses for a computer system.
  • Multiple bus architecture allows multiple devices to work at the same time. This reduces waiting time and enhances the speed of the computer as compared to single bus architecture in which all the components share a common bus. Sharing a common bus causes bus contention which results in slowing down the computer and waiting time increases.
  • Having several different buses available allows to have multiple choices for connecting devices to computer system.
  • Bus designs changes, with the introduction of new types and forms from time to time. Multiple bus architecture with several buses can support equipment from different time periods and helps to retain obsolete equipment such as printers and old hard drives, and also add new ones. This is the compatibility benefit of using multiple bus architecture.
  • CPU places heavy load on bus which carries data from memory and peripheral traffic. So nowadays computers take on multi core model with multiple buses required. So multiple bus architecture is a good option for such systems as it carries more amounts of data through the processor with minimum wait time.

3 0
2 years ago
Other questions:
  • Your organization will be handling market trades. You will be required to verify the identify of each customer who is executing
    8·1 answer
  • I just want to ask if some one know an online school program that offer a live session and the cost of it not to expensive. for
    10·1 answer
  • When are number list generally used ?
    10·1 answer
  • #11. Write a program that prompts the user to input a four-digit positive integer. The program then outputs the digits of the nu
    6·1 answer
  • The piece of hardware that contains the circuitry that processes the information coming in to the computer and tells the other h
    8·1 answer
  • 1. Which of the following statements are true about routers and routing on the Internet. Choose two answers. A. Protocols ensure
    9·2 answers
  • Green field country is planning to conduct a cricket match between two teams A and B. a large crowd is expected in the stadium a
    6·1 answer
  • Integer indexing array: Weekend box office The row array movieBoxOffice stores the amount of money a movie makes (in millions of
    11·1 answer
  • Phoebe is a Counselor who is trying to schedule a meeting with one of her patients. Which best describes an inappropriate locati
    10·2 answers
  • Desktop computers have a(n) ________ unit, located within the system unit, that plugs into a standard wall outlet, converts AC t
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!