MATLAB 绘图点的颜色基于与线的距离

MATLAB plot point with color based on distance from line

我在 MATLAB 的二维空间中有一组 m 点和一组 n 线。假设 n 线以 n 颜色绘制,我需要用它所在的线组的 平均颜色 的颜色绘制每个点最靠近。我可以计算点与线的距离,但是如何使用 scatter 将点的颜色设置为由距离它最近的线的距离加权的值?

该示例应该对您有所帮助:

clear all;
close all;

m = 20; %number of points
markerSize = 25;

%example points
a=rand(2,m);
a(:,m-1) = [0;0]; % this point will be purple
a(:,m-2) = [1;0]; % this point will be blue
a(:,m-3) = [0;1]; % this point will be red

%line x=0 is red
%line y=0 is blue;
f1 =figure(1);
hold on;
for i = 1:m
    pointColor = [1-a(1,i) 0 1-a(2,i)]; % rgb format - calculate distance here
    % [0 0 0] - black , [1 1 1] - white
    % pointColor=(lineColor1*distance1 + lineColor2*distance2+...)/numberOfClosestLines;
    scatter(a(1,i),a(2,i),markerSize, pointColor)
end