首页 > > 详细

data留学生辅导、java程序语言调试、辅导Java设计 解析C/C++编程|辅导Python编程

Functions and Recursion – 55 course points
This assignment consists of two parts. First, write a library of static methods that
performs geometric transforms on polygons. Next, write a program that plots
a Sierpinski triangle.
Programming
Write 2 programs and submit on Sakai.
We provide a zip containing PolygonTransform.java, and Sierpinski.java. For each
problem update and submit the corresponding file.
DO NOT use System.exit()
DO NOT add any import statements
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 print the result as specified by the example for each problem.
DO NOT print other messages, follow the examples for each problem.
USE StdIn, StdOut, and StdDraw libraries.
1. 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 (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[].
Three useful geometric transforms are scale, translate and rotate.
Scale the coordinates of each vertex (x i, y i) by a factor α.
x‘i = α xi
y‘i = α yi
Translate each vertex (x i, y i) by a given offset (dx, dy).
x‘i = xi + dx
y‘i = yi + dy
Rotate each vertex (x i, y i) by θ degrees counterclockwise, around the origin.
x‘i = xi cos θ – yi sin θ
y‘i = yi cos θ + xi sin θ
Write a two-dimensional transformation library by implementing the following API:
3. Sierpinski (30 points). The Sierpinski triangle is an example of a fractal pattern
like the H-tree pattern from Section 2.3 of the textbook.
The Polish mathematician Wacław Sierpiński described the pattern in 1915, but it
has appeared in Italian art since the 13th century. Though the Sierpinski triangle
looks complex, it can be generated with a short recursive function. Your main
task is to write a recursive function sierpinski() that plots a Sierpinski triangle of
order n to standard drawing. Think recursively: sierpinski() should draw one filled
equilateral triangle (pointed downwards) and then call itself recursively three
times (with an appropriate stopping condition). It should draw 1 filled triangle for n
= 1; 4 filled triangles for n = 2; and 13 filled triangles for n = 3; and so forth.
API specification. When writing your program, exercise modular design by organizing it
into four functions, as specified in the following API:
Restrictions: You may not change either the scale or size of the drawing window.
Before submission
1. Collaboration policy. Read our collaboration policy here.
2. Update @author. Update the @author tag of the files with your name, email and
netid.
3. Submitting the assignment. Submit PolygonTransform.java, and Sierpinski.java
separately on Sakai.

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!