Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please write code in java. Observe the following rules DO NOT use System exito DO NOT add the project or package statements DO NOT change

image text in transcribedplease write code in java.
image text in transcribed
image text in transcribed
image text in transcribed
Observe the following rules DO NOT use System exito DO NOT add the project or package statements DO NOT change the class name. DO NOT change the headers of ANY of the given methods DO NOT add any new class fields ONLY display the result as specified by the example for each problem DO NOT print other messages, follow the examples for each problem USE Sidin, Sidout SidRandom and Sid Draw libraries Polygon transform (25 points) Write a library of Static methods that performs various geometric transforms on polygons Mathematically, a polygon is defined by its sequence of vertices Yol X1) X 2.) In Java, we will represent a polygon by storing the -and y coordinates of the vertices in two parallel arrays and y . Here to the lyrics 02). double (11) double Y. 2.1 Three useful geometric transforms are scale, translate and rotate Scale the coordinates of each vertex (x,y) by a factor a Xi-axi yira y Translate each vertex (x, y) by a given offset (dx, dy) x1 = x + dx Vi= y + dy Rotate each vertex (x, y) by e degrees counterclockwise, around the origin X; = x;cos e- y sin e Y;= y, cos @ + x, sin e Write a two-dimensional transformation library by implementing the following API public class Polygon Transform // Returns a new array object that is an exact copy of the given array: // The given array is not mutated. public static double1 copy(double[] array) 1/ Scales the polygon by the factor alpha public static void scaledouble[] , double y, double alpha) 7 Translates the polygon by (dx, dy public static void translate(doublecl *. doublefly, double dx, double dy) W Rotates the polygon theta degrees counterlaced about the origins public static void rotate(double] , double() y, double theta) 17 Tests each of the APT methods by directly calling them public static void main(String args) Note that the transformation methods scale), translate() and rotate() mutate the polygons. Here are some example test cases (tests for copy) are not shown) 1/ Scales polygon by the factor 2 straw.setScale(-5.0, 5.0); double) * - , 1, 1, 0) poublely - (0, 0, 2, 1); souble alpha - 2.0 Store.setPencolor (St Draw,RED): Strapolygon. ) scale(x, Y. alpha) straw.setPenColor(5tdraw.BLUE); straw.polygon (x, y): // Translates polygon by (2.1). Straw.setScale(-5.0, 5.0) doublell X - [ 0, 1, 1); doublefly - {0, 0, 2, 1); double dx - 2.0, dy - 1.0 stobrau.setPen Color (Str.RO): Straw.polygon(x, y): translate(x, y, dx dy): Storiw.setPencolor (Stora. U Str.polygon. ) 11 Rotates polygon 45 degrees stran.setScale(-5.0, 5.0); Houble] - (1. 1. ) Joublecl y .(0, , 2, 1): Jouble theta - 45.0 KtDraw, setpencolor (Straw.RED): Straw.polygon, Y): rotate(x, y, theta); Story.setPencolor (Straw. BLUE) Straw.polygon. Y): 10.0 100 100

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

12-5 How will MIS help my career?

Answered: 1 week ago