Question: Your input: The scaffold code is set up to ask you to input a number, specifying which file to open (1, 2, 3, or 4,

Your input:

The scaffold code is set up to ask you to input a number, specifying which file to open (1, 2, 3, or 4, representing either input1.in, input2.in, input3.in, or input4.in). The input files will be used to create the following two matrices:

  • A 23 matrix L will be created using the first two lines of the selected input file.

  • A 33 matrix P will be created using the last three lines of the selected input file.

Explanation of the input:

  • The matrix L represents a line L in R3:

    • The first row of L represents the coordinates of a point A on L.

    • The second row of L represents a direction vector d parallel to L.

  • The matrix P represents a plane P in R3:

    • The first row of P represents the coordinates of a point B on P.

    • The second row of P represents a direction vector u parallel to P.

    • The third row of P represents a direction vector v parallel to P. You may assume that u and v are not parallel to one another.

Before proceeding to the next section, look at each of the input files input1.in, input2.in, input3.in, and input4.in, and determine the equations of the corresponding line L and plane P in vector form, to make sure that you understand how to interpret the input files. You may also find it helpful to convert these equations to some of the other forms we have studied in lectures and tutorials; for example, general form or normal form.

Relationship between L and P:

There are four possibilities for the geometric relationship between the line L and the plane P:

  1. The line and plane do not intersect.

  2. The line lies on the plane (i.e. the intersection of the line and plane is the line itself).

  3. The line intersects the plane at a single point, and the line is perpendicular to the plane.

  4. The line intersects the plane at a single point, and the line is not perpendicular to the plane.

Your task:

Write code that determines the relationship between the line L and plane P described by L and P, and then assigns the variable rel a value of 1, 2, 3, or 4 corresponding to the correct relationship, as described in the list above. (The scaffold code sets rel to be 0 in line 21, but please delete this line and replace it with your own code.)

For instance, if your code determines that the line intersects the plane at a single point, and the line is perpendicular to the plane, then you should set rel to be 3. (See the example at the end of these instructions for a more detailed explanation of this.)

fflush(stdout); file = input("Input file number (1, 2, 3, or 4): "); if file > 4 matrix = dlmread(stdin); elseif file <= 4 basename = "input"; ending = ".in"; filename = sprintf("%s%d%s",basename,file,ending); matrix = dlmread(filename); else printf(" Error: no file number entered.") exit(1) end L = matrix(1:2,:); P = matrix(3:5,:); clear file matrix ###### Do not modify anything above this line. Type your code below it. ######

###### Replace the code in this section with your own code that correctly sets the value of rel to 1, 2, 3, or 4, depending on the relationship between the line L and the plane P. ######

rel = 0;

###### Do not modify anything below this line. Type your code above it. ###### printf(" Relationship: ") dlmwrite(stdout,rel) switch rel case 1 printf(" L and P do NOT intersect. ") case 2 printf(" L lies on P. ") case 3 printf(" L intersects P once and is perpendicular to P. ") case 4 printf(" L intersects P once and is NOT perpendicular to P. ") otherwise printf(" Error: invalid relationship. ") end

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!