Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

def coarsen ( terrain ) : x = terrain.points [ : , 0 ] y = terrain.points [ : , 1 ] z = terrain.points

def coarsen(terrain):
x = terrain.points[:,0]
y = terrain.points[:,1]
z = terrain.points[:,2]
# Reshape the coordinate arrays to match the dimensions of the terrain mesh
x = x.reshape(terrain.dimensions, order='F')
y = y.reshape(terrain.dimensions, order='F')
z = z.reshape(terrain.dimensions, order='F')
# Sample every other point along each axis
x_coarse = x[::2, ::2]
y_coarse = y[::2, ::2]
z_coarse = z[::2, ::2]
# Calculate the new dimensions
new_dims =((terrain.dimensions[0]//2)+1,(terrain.dimensions[1]//2)+1,1)
# Create the new coarser mesh as a StructuredGrid
coarse = pv.StructuredGrid(x_coarse.ravel('F'), y_coarse.ravel('F'), z_coarse.ravel('F'))
return x_coarse, y_coarse, z_coarse, coarse
#grade (write your code in this cell and DO NOT DELETE THIS LINE)
#NOTE: You do not need to round any values within your results.
def bilin(x, y, points):
# YOUR CODE HERE
# raise NotImplementedError()
# to keep unique x and y coordinate
x_set = set()
y_set = set()
# to be able to get value at the coordinate quickly
points_dict ={}
for point in points:
# add coordinates to set and dict
x_set.add(point[0])
y_set.add(point[1])
points_dict[(point[0], point[1])]= point[2]
# turn it to list
x_list = list(x_set)
y_list = list(y_set)
# sort the list
x_list.sort()
y_list.sort()
# print(x_list)
# print(y_list)
# print(points_dict)
# calculate t ratio for x
t_x =( x - x_list[0])/( x_list[1]- x_list[0])
# print(t_x)
# calculate first bilinear interpolation for x axis
bilin_bottom =(1- t_x )* points_dict[(x_list[0], y_list[0])]+( t_x * points_dict[(x_list[1], y_list[0])])
bilin_top =(1- t_x )* points_dict[(x_list[0], y_list[1])]+( t_x * points_dict[(x_list[1], y_list[1])])
# print(bilin_bottom)
# print(bilin_top)
# calculate t ratio for y
t_y =( y - y_list[0])/( y_list[1]- y_list[0])
# return bilinear interpolation for y axis
return (1- t_y )* bilin_bottom + t_y * bilin_top
Now, using your bilin() function, create a new mesh or StructuredGrid object named intmesh, reconstructed from coarse using bilinear interpolation, with the same dimensions as our original mesh terrain. Your new mesh should contain the interpolated z-values for each point in terrain.
As a starting point, we have defined some of the variables that will be helpful to you for creating your new interpolated mesh. Specifically, we will be checking the values in errz and intz, as defined below:
intz: a 3D array with the same shape as terrain.z that will contain the bilinearly interpolated z-values from the coarsened mesh.
Note: intz is a 3D M x N x 1 array where the last dimension contains the z-values. You should note this when assigning elements to intz. The interpolated mesh is a 3D M by N by 1 array, so tests will fail if you assign values to it as if it were just a 2D M by N array, bypassing the z-axis entirely. So, if your code looks like intz[x][y]= bilin(...) the fix is to change it to something like intz[x][y]=[ bilin(...)] or intz[x][y][0]= bilin(...).
errz: a list of scalar values. This should contain the absolute error values between each z-value in the original mesh and each interpolated z-value in the new returned mesh
Just like how we added the attribute values to our coarse mesh in order to plot the z-values of the mesh, you should add an additional attribute errors to intmesh in order to plot the absolute error values between the z-values in the original mesh and the interpolated z-values in our new returned mesh.
In the code block below, complete the implementation of reconstructMesh(terrain,coarse), which should return a tuple containing (intz, errz, intmesh).

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_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

Database Design Query Formulation And Administration Using Oracle And PostgreSQL

Authors: Michael Mannino

8th Edition

1948426951, 978-1948426954

More Books

Students also viewed these Databases questions

Question

2. What are implementation intentions?

Answered: 1 week ago

Question

Create a workflow analysis.

Answered: 1 week ago