Answered step by step
Verified Expert Solution
Question
1 Approved Answer
i need e1.7 but here is e1.6 as reference I. Requires Exercise (E1.6). A polygon with n vertices is represented as an array with n
i need e1.7 but here is e1.6 as reference
I. Requires Exercise (E1.6). A polygon with n vertices is represented as an array with n rows and 2 columns. Consider the following functions: computeDistancePointToPolygon (15 points) Input: a polygon P and a point q. Output: the distance from q to the closest point in P, called the distance from q to the 9 9 polygon. computeTangentVectorToPolygon (15 points) Input: a polygon P and a point q. Output: the unit-length vector u tangent at point q to the polygon P in the following sense: (i) if q is closest to a segment of the polygon, then u should be parallel to the segment, (ii) if q is closest to a vertex, then u should be tangent to a circle centered at the vertex that passes through q, and (iii) the tangent should lie in the counter-clockwise 9 direction Hint: You are allowed to use the Matlab function inpolygon to check if the point is inside the polygon, but watch out that Matlab uses a different convention to describe polygons. Hint: Determine which segment or vertex of P is closest to q to determine whether to use the segment or vertex tangent case. For each function, do the following: (i) explain how to implement the function, possibly deriving analytic formulas, and characterize special cases, (i) program the function, including correctness checks on the input data and appropriate error messages, and (iii) verify your function is correct on a broad range of test inputs. Programming Note: It is convenient to learn to visualize points, vectors and polygons in your chosen programming environment. To visualize a red square in Matlab (RGB triplet (1,0,0]), one can execute the commands: E1.6 Programming: Lines and segments (30 points). In this exercise you are asked to begin implementing a number of basic algorithms that perform geometric computations. Consider the following planar geometry functions: computeLineThroughTwoPoints (10 points) Input: two distinct points P1 (1, y) and P2 = (22,92) on the plane. Output: parameters (a, b, c) defining the line {(x,y) | ar+by+c=0} that passes through both p and p2. Normalize the parameters so that a + b = 1. computeDistancePointToLine (10 points) Input: a point q and two distinct points p1 = (x1, y) and p2 = (22,y) defining a line. Output: the distance from q to the line defined by P1 and 22. 9 computeDistancePointToSegment (10 points) Input: a point q and a segment defined by two distinct points (PP). Chapter 1. Sensor-based Planning Output: (d, w), where d is the distance from a to the segment with extreme points (P2) and w {0,1,2] has the following meaning: w = 0 if the segment point closest to q is strictly inside the segment, w = 1 if the closest point is P, and = 2 if the closest point is pa For each function, do the following: (1) explain how to implement the function, possibly deriving analytic formulas, and characterize special cases, (ii) program the function, including correctness checks on the input data and appropriate error messages, and (ii) verify your function is correct on a broad range of test inputs. Hint: To check two points are distinct, use a tolerance equal to 10 Regarding the func tion computeDistancePointToLine, compute the orthogonal projection of onto the line Regarding computeDistancePointToSegment, the distance depends on whether or not the Orthogonal projection of onto the line defined by and p, belongs or not to the segment between and pa I. Requires Exercise (E1.6). A polygon with n vertices is represented as an array with n rows and 2 columns. Consider the following functions: computeDistancePointToPolygon (15 points) Input: a polygon P and a point q. Output: the distance from q to the closest point in P, called the distance from q to the 9 9 polygon. computeTangentVectorToPolygon (15 points) Input: a polygon P and a point q. Output: the unit-length vector u tangent at point q to the polygon P in the following sense: (i) if q is closest to a segment of the polygon, then u should be parallel to the segment, (ii) if q is closest to a vertex, then u should be tangent to a circle centered at the vertex that passes through q, and (iii) the tangent should lie in the counter-clockwise 9 direction Hint: You are allowed to use the Matlab function inpolygon to check if the point is inside the polygon, but watch out that Matlab uses a different convention to describe polygons. Hint: Determine which segment or vertex of P is closest to q to determine whether to use the segment or vertex tangent case. For each function, do the following: (i) explain how to implement the function, possibly deriving analytic formulas, and characterize special cases, (i) program the function, including correctness checks on the input data and appropriate error messages, and (iii) verify your function is correct on a broad range of test inputs. Programming Note: It is convenient to learn to visualize points, vectors and polygons in your chosen programming environment. To visualize a red square in Matlab (RGB triplet (1,0,0]), one can execute the commands: E1.6 Programming: Lines and segments (30 points). In this exercise you are asked to begin implementing a number of basic algorithms that perform geometric computations. Consider the following planar geometry functions: computeLineThroughTwoPoints (10 points) Input: two distinct points P1 (1, y) and P2 = (22,92) on the plane. Output: parameters (a, b, c) defining the line {(x,y) | ar+by+c=0} that passes through both p and p2. Normalize the parameters so that a + b = 1. computeDistancePointToLine (10 points) Input: a point q and two distinct points p1 = (x1, y) and p2 = (22,y) defining a line. Output: the distance from q to the line defined by P1 and 22. 9 computeDistancePointToSegment (10 points) Input: a point q and a segment defined by two distinct points (PP). Chapter 1. Sensor-based Planning Output: (d, w), where d is the distance from a to the segment with extreme points (P2) and w {0,1,2] has the following meaning: w = 0 if the segment point closest to q is strictly inside the segment, w = 1 if the closest point is P, and = 2 if the closest point is pa For each function, do the following: (1) explain how to implement the function, possibly deriving analytic formulas, and characterize special cases, (ii) program the function, including correctness checks on the input data and appropriate error messages, and (ii) verify your function is correct on a broad range of test inputs. Hint: To check two points are distinct, use a tolerance equal to 10 Regarding the func tion computeDistancePointToLine, compute the orthogonal projection of onto the line Regarding computeDistancePointToSegment, the distance depends on whether or not the Orthogonal projection of onto the line defined by and p, belongs or not to the segment between and pa 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