Cody

# Problem 45313. Find the shortest distance between a point and a straight line.

Solution 2132531

Submitted on 18 Feb 2020 by Asif Newaz
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
x1 = [0 0 0]; x2 = [1 1 1]; x3 = [2 2 2]; y_correct = 0; eps = 4.999 * 10^(-7); assert(abs(shortest_distance(x1,x2,x3)-y_correct)<eps)

2   Pass
x1 = [0 0 0]; x2 = [0 0 1]; x3 = [1 0 0]; y_correct = 1; eps = 4.999 * 10^(-7); assert(abs(shortest_distance(x1,x2,x3)-y_correct)<eps)

3   Pass
x1 = [1 0 0]; x2 = [0 1 0]; x3 = [0 0 0]; y_correct = sqrt(1/2); eps = 4.999 * 10^(-7); assert(abs(shortest_distance(x1,x2,x3)-y_correct)<eps)

4   Pass
theta = 0.5; psi = -0.2; phi = 1.1; R3=[cos(psi) sin(psi) 0.0; -sin(psi) cos(psi) 0.0; 0.0 0.0 1.0]; R2=[cos(theta) 0.0 -sin(theta); 0.0 1.0 0.0; sin(theta) 0.0 cos(theta)]; R1=[1.0 0.0 0.0; 0.0 cos(phi) sin(phi); 0.0 -sin(phi) cos(phi)]; R = R3*R2*R1; x1 = [1 0 0]*R; x2 = [0 1 0]*R; x3 = [0 0 0]*R; y_correct = sqrt(1/2); eps = 4.999 * 10^(-7); assert(abs(shortest_distance(x1,x2,x3)-y_correct)<eps)

5   Pass
x1 = [0 0 0]; x2 = [0 0 1]; x3 = x2; y_correct = 0; eps = 4.999 * 10^(-7); assert(abs(shortest_distance(x1,x2,x3)-y_correct)<eps)