Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

square.dat - Notepad hyp - veh - cross - sect . dat - Notepad File Edit Format View Help 9 . 0 9 0 9

square.dat - Notepad hyp-veh-cross-sect.dat - Notepad
File Edit Format View Help
9.0909090.04899,699.049
9.012819,0.047931,609.041
0.0257570.047448,609.045
9.9399680.946614699.654
9.053210.045369,699.069
9.668419,0.043638,609.097
9.0847750.041366609.153
9.098186,0.039212,609.236
0.112420.036749600.385
0.125850.034282609.631
9.138220.031902601.015
0.149580.029695601.695
0.169210.027429,602.477
0.179610.025199603.869
0.180610.023049605.913
9.189920.029978,698.993
0.199050.018942613.279
9.297860.016968619.498
9.216190.015977,628.041
0.223620.013418,638.369
9.23130.911737,652.364
9.237540.010373666.954
0.24398,0.0973646,711.909
9.24488,9.6959749,759.694
0.24630.699909999.099
9.24457-0.6949436,1037.301
9.24242-0.6979272,1981.827
9.23607-0.0992998,1119.049
0.22791-0.0999961,1128.429
9.21548-0.01112,1141.439
9.20556-0.012064,1159.679
9.19975-0.013473,1162.024
9.18142-0.014378,1167.976
9.17111-0.0153631173.449
9.16032-0.016399,1178.238
9.14843-0.017512,1182.454
0.13565,-0.01869,1186.051
9.12163-0.019949,1189.109
9.10593-0.0212951191.636
9.088838-0.022663,1193.617
9.071585-0.023891,1194.995
9.056165-0.02481,1195.830
9.041541-0.025501,1196.365
9.027531-0.025982,1196.696
0.013757-0.026269,1196.880
9.090999-0.026366,1196.939
-0.013757,-0.026269,1196.880
-0.027531-0.025982,1196.696
-0.041541-0.0255011196.365
-0.056165-0.02481,1195.830
-0.071585-0.023891,1194.995
-0.088838-0.0226631193.617
-0.10593-0.021295,1191.636
-0.12163-0.0199491189.109
-0.13565-0.01869,1186.051
-0.14843-0.017512Define a class called Boundary to represent a polygonal domain with temperature values at the polygon vertices. Implement two methods: __init__ and distance_to_closest_edge. The points of the polygon and temperatures are supplied in a text file. The __init__ method should read that file and store values in a manner of your choosing. Here is an example file that corresponds to an square domain, note that the final line repeats the first point. This was a deliberate choice in the file representation. Other representations are possible but this one makes coding convenient when treating consecutive points as defining edges. In this file column 1 is x position of a point, column 2 is y position and column 3 is the temperature value. Each row represents a point plus its temperature.
0.00.0600.0
1.00.0700.0
1.01.01000.0
0.01.0850.0
0.00.0600.0
The other method to write is distance_to_closest_edge. For a given point interior to the polygon, this method should locate the closest edge and find the distance to the closest point on the line segment of that closest edge. You should make use of the function you built earlier: closest_point_on_line_segment. You will need to treat every edge of the polygon as a line segment and test all edges in turn to find the closest. When you have found the closest, return a tuple of form (edge_index, distance). The
edge_index (integer) is defined as the index of the first point on the segment. The distance is the closest distance to the closest edge that you located.
The code snippet below shows the skeleton of what is required for the Boundary class in this task.
class Boundary():
def __init__(self, filename):
"""Reads filename and stores points and temperature values for later use."""
def distance_to_closest_edge(self, p):
"""Given point p, return (edge_index, distance) of closest edge and distance to
,-> that edge."""
We can test this code using a square. The file is square.dat.
>>> square = Boundary("square.dat")
>>> square.distance_to_closest_edge<

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

Recommended Textbook for

Linked Data A Geographic Perspective

Authors: Glen Hart, Catherine Dolbear

1st Edition

1000218910, 9781000218916

More Books

Students also viewed these Databases questions