Question: Python 3!! By creating and using the helper functions 1-8, build a step by step solution to the main function which implements all of the

Python 3!!

By creating and using the helper functions 1-8, build a step by step solution to the main function which implements all of the given helper functions. The notes under each function name will serve as a guide to writing the code. Do not use numpy, or any other packages.

The algorithm to solving the main function is as follows:

Let L1 and L2 be lines in 2-space.

Let H1= (a1, b1, c1) be a homogeneous representation of the line L1, and let H2= (a2, b2, c2) be a homogeneous representation of the line L2.

Then the intersection of L1 and L2 is the point H1H2 (cross product) in projective 2-space.

1. def Unit (v):

"""Normalize a vector.

Params: v (float 2-tuple): a vector in 2-space

Returns: (float 2-tuple) unit vector (Euclidean length 1) in same direction

"""

return

2. def PPtoPV (PP):

"""Translate from 2-point to point-vector representation of a line.

Params: PP (float 4-tuple): 2-point representation of a line: px,py,qx,qy

Returns: (float 4-tuple): point-vector rep of the line: px,py,vx,vy

note that the vector is unit

"""

return

3. def PVtoPN (PV):

"""Translate from point-vector to point-normal representation of a line.

Alg: if V = (v0,v1), N = (-v1,v0)

(so their inner product is 0, so their angle is pi/2)

Params: PV (float 4-tuple): point-vector rep of a line: px, py, vx, vy

the vector is unit

Returns: (float 4-tuple): point-normal rep of the line: px, py, nx, ny

the normal is unit

"""

return

4. def PNtoHomog (PN):

"""Translate from point-normal to homogeneous representation of a line.

Params: PN (float 4-tuple): point-normal rep of a line: px, py, nx, ny

the normal is unit

Returns: (float 3-tuple): homogeneous representation (a,b,c) of the line

"""

return

5. def PPtoHomog (L):

"""Translate from 2-point to homogeneous representation of a line.

Params: L (float 4-tuple) 2-point representation (x1,y1,x2,y2) of a line

Returns: (float 3-tuple) homogeneous representation (a,b,c) of the line

"""

return

6. def cross (a,b):

"""Cross product of 2 vectors in 3-space (or projective 2-space).

(Foreshadowing: this is a built-in function in numpy.)

Params: a (float 2-vector) a vector in 2-space

Params: b (float 2-vector) a vector in 2-space

Returns: a x b

"""

return

7. def LiLiIntersect_proj (L1, L2):

"""Intersect two lines in projective space.

Params:

L1 (float 4-tuple): first line, defined by two points x1, y1, x2, y2

L2 (float 4-tuple): second line, also defined in 2-point rep

Returns: (3-tuple) intersection point in projective 2-space

(this intersection is at infinity if its 3rd coord is 0)

"""

return

8. def ProjToEuc (P):

"""Translate a fine point in projective 2-space to Euclidean 2-space.

Params: P (float 3-tuple) finite point in projective 2-space

Returns: (float 2-tuple) associated point in Euclidean 2-space

"""

return

MAIN FUNCTION= def LiLiOblique (L1, L2):

return

"""Intersect two oblique lines in Euclidean space.

Since two lines are oblique (not parallel), intersection is finite.

Params:

L1 (float 4-tuple): first line, defined by two points x1, y1, x2, y2

L2 (float 4-tuple): second line, also defined in 2-point rep

Returns: (float 2-tuple) intersection point in Euclidean space

"""

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!