Answered step by step
Verified Expert Solution
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 hypvehcrosssectdat Notepad
File Edit Format View Help
Define a class called Boundary to represent a polygonal domain with temperature values at the polygon vertices. Implement two methods: init and distancetoclosestedge. 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 is x position of a point, column is y position and column is the temperature value. Each row represents a point plus its temperature.
The other method to write is distancetoclosestedge. 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: closestpointonlinesegment. 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 edgeindex, distance The
edgeindex 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 initself filename:
Reads filename and stores points and temperature values for later use."""
def distancetoclosestedgeself p:
Given point p return edgeindex, distance of closest edge and distance to
that edge."""
We can test this code using a square. The file is square.dat.
square Boundarysquaredat"
square.distancetoclosestedge
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started