代写算法作业,使用marching squares算法绘图。
Requirement
In this assignment you will implement the marching squares algorithm in order
to draw approximations of the 2D boundary of implicit equations.
Your tasks are summarized in the following items:
Grid
You will use a grid to determine the size of each square. The grid has to be
implemented with the following controls:
z: will switch between drawing the grid at the screen or hiding it
q: will increase the resolution of the grid
a: will reduce the resolution of the grid
Evaluation
Each cell of the grid represents an evaluation square of the marching squares
algorithm. Therefore each vertex of the grid represents one evaluation point.
In order to show the result of the point evaluations, at each grid vertex you
will have to draw a small circle or square around the grid vertex with two
possible colors. One color meaning that the point was evaluated as inside the
curve, and another color for when the point is evaluated outside.
x: will switch between drawing the evaluation points or hiding them
Curve Approximations
You will then apply the marching square rules to connect lines approximating
the boundary of the implicit curve being evaluated. Automatically recompute
and update these lines every time a key is pressed for changing the grid
resolution.
Curve Selection
You will have to implement in your code at least five different implicit
curves, and allow the user to switch between them by pressing keys 1,2,3,4,5.
At least two curves have to generate more than one connected component (more
than one “separate boundary”).
Here are some curves you may use to test your code:
x^2-y^2=1
x^2 + y^2 + sin4x + sin4y = 1
Quadtree Adaptive Subdivision
For this last requirement you will implement in your code an adaptive
subdivision of your grid, following the quadtree hierarchical decomposition
scheme. The adaptive resolution is achieved by only further subdividing the
cells with mixed evaluations. Given the current global resolution (Requirement
1), you will advance in adaptive resolution increases whenever the W key is
pressed. The idea is to first perform global evaluations with the global grid
resolution, and then proceed with adaptive resolution.
Key controls
w: will increase the maximum depth of the adaptive quadtree, increasing the
overall resolution of the approximation
s: will decrease the maximum depth of the adaptive quadtree, decreasing the
overall resolution of the approximation
Here is an example from the lecture slides illustrating the quadtree
subdivision scheme applied at two quadrands.