FindClosestPoint

Given a line AB, and a point C, find point D on line AB that is closest to C.
80 Downloads
Updated 27 Apr 2016

View License

% [D,lambda,isConvex] = findClosestPoint(A,B,C)
%
% Given a line segment AB, and an arbitrary point C, compute the point D on
% the line AB which is closest to point C.
%
% INPUTS:
% A = [2,n] = [Ax;Ay] = First point on the line
% B = [2,n] = [Bx;By] = Second point on the line
% C = [2,n] = [Cx;Cy] = Arbitrary point of interest
%
% OUTPUTS:
% D = [2,n] = [Dx;Dy] = point on AB that is nearest to C
% lambda = [1,n] = lagrange multiplier: D = lambda*A + (1-lambda)*B
% isConvex = true if D is a convex combination of A and B
% isConvex = lambda >=0 && lambda <= 1
%

Cite As

Matthew Kelly (2026). FindClosestPoint (https://www.mathworks.com/matlabcentral/fileexchange/56791-findclosestpoint), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2012a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Spatial Search in Help Center and MATLAB Answers
Version Published Release Notes
1.0.0.0