Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(MATLAB) A standard form of the equation of a line is Ax + By + C = 0. Write a f

ID: 2259933 • Letter: #

Question

(MATLAB) A standard form of the equation of a line is Ax + By + C = 0. Write a function to determine the distance between a given point and a given line.

For the function name and arguments, use:
      d = PtDist(x,y,A,B,C)
where the input arguments are the coordinates of the point and the three constants for the equation of the line. The output argument is the distance. The point of intersection can be found using the following formula:

x = x0 + m * y0 mb / 1 + m^2,     y = mx0 + m^2 * y0 + b / 1 + m^2

Explanation / Answer

%%% Function

function [d]=PtDist(x0,y0,A,B,C)
d=abs((A*x0+B*y0+C)/sqrt(A^2+B^2));

end

%%% test programme

clc;
clear all;
close all;
A=2;
B=-4;
C=4;
x0=1;
y0=3;
d=PtDist(x0,y0,A,B,C);
fprintf('Distance between point (%d,%d) and line %dx+ %dy +%d =0 is : %f ',x0,y0,A,B,C,d)

OUTPUT:

Distance between point (1,3) and line 2x+ -4y +4 =0 is : 1.341641