Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a function perpendicular() which determines whether two 2D vectors are perpendicular to each other. In order to make this determination, we will compute two

Write a function perpendicular() which determines whether two 2D vectors are perpendicular to each other. In order to make this determination, we will compute two perpendicular vectors from a given vector (x, y). The first perpendicular vector, (px1, py1), is defined as px1 = y and py1 = x. The second perpendicular vector, (px2, py2), is defined as px2 = px1 and py2 = py1. For example if (x, y) = (1, 2) then (px1, py1) = (2, 1) and (px2, py2) = (2, 1). Thus, (px1, py1) and (px2, py2) are perpendicular vectors to (x, y). You must implement the following algorithm to determine if two vectors, (x1, y1) and (x2, y2), are perpendicular:

(a) Normalize (x1, y1) and (x2, y2); Lets call the new vectors v1 = (vx1, vy1) and v2 = (vx2, vy2), respectively (use better variable names). Call the normalize() function to compute these. Note that v1 and v2 are unit vectors.

(b) Compute two perpendicular vectors to v1 (see instructions above). Lets call the two new vectors p1 and p2.

(c) Check whether v2 is the same as either p1 or p2. If so, then output Vectors are PERPENDICULAR. to the screen. Otherwise, output Vectors are NOT PERPENDICULAR. See next step for more details.

(d) Let p1 = (px1, py1), and p2 = (px2, py2).

i. To determine if v2 is the same vector as p1, check that both vx2 = px1 and vy2 = py1. Use EPSILON as described in step 4 above to determine each equality.

ii. To determine if v2 is the same vector as p2, check that both vx2 = px2 and vy2 = py2. Use EPSILON as described in step 4 above to determine each equality.

Define the function so that it does not return a value and has four parameters that are all passed by value:

a number x1 of type double representing the x coordinate of the first 2D vector.

a number y1 of type double representing the y coordinate of the first 2D vector.

a number x2 of type double representing the x coordinate of the second 2D vector;

a number y2 of type double representing the y coordinate of the second 2D vector.

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

The Manga Guide To Databases

Authors: Mana Takahashi, Shoko Azuma, Co Ltd Trend

1st Edition

1593271905, 978-1593271909

More Books

Students also viewed these Databases questions