【问题标题】:Rotate polarplot and store interception values旋转极坐标图并存储截距值
【发布时间】:2021-11-29 14:21:10
【问题描述】:

假设我有一个极坐标图

theta = 0:0.01:2*pi;
rho = sin(theta)-5;
polarplot(theta,rho)

如何以 1 度为步长旋转该图并存储曲线与每一步的 x 和 y 轴的截距?

【问题讨论】:

标签: matlab plot polar-coordinates


【解决方案1】:

我试了一下解决这个问题,希望对你有帮助:

%Define number of samples - more samples = more accurate but a slower computation
samples = 100000;
k = 5; % Number of circles overlapping each other
theta = linspace(0, 2*pi, samples);
c = 1;
rho = zeros(samples,k);

%List all pairs of circles
a = linspace(1,size(rho,2),k);
b = linspace(1,size(rho,2),k);
[A,B] = meshgrid(a,b);
d=reshape(cat(2,A',B'),[],2);
for p = 1:length(d)
   if(d(p,1) < d(p,2))
      stash = d(p,1);
      d(p,1) = d(p,2);
      d(p,2) = stash;
   end
end
%Ensure unique pairs
pairs = unique(d,'rows');
pairs = pairs(any(diff(pairs,1,2),2),:);

%Plot and find intercept points
for r = linspace(0,2,k)
    rho(:,c) = sin(theta-r)-5;
    polarplot(theta,rho(:,c))
    hold on;
    c = c + 1;
end

values = zeros(1,2);
vec = linspace(0,2,k);
point1 = 0;
%Loop over every data sample
for x = 1:samples
    for y = 1:size(pairs,1)
        if abs(rho(x,pairs(y,1))-rho(x,pairs(y,2))) < 0.0001 %Check if lines overlap
            point1 = x;
        end
        
        %Save data if point is overlapping
        if point1 ~= 0
            Xvalues = theta(point1);
            Yvalues = sin(theta(point1)-vec(pairs(y,2)))-5;
            values = [values; Xvalues, Yvalues ];
            point1 = 0;
        end
    end
end

%Intercept points are stored in values
values(1,:) = [];
values = round(values,2); %Round values to 2 decimals
values = unique(values,'rows'); %Ensure no repeating values are found

%Plot points here - values have (theta, rho) points
for x = 1:length(values)
    polarplot(values(x,1),values(x,2),'r*')
end

Plot obtained with 19 overlapping circles

【讨论】:

  • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-21
  • 1970-01-01
  • 2016-10-06
  • 1970-01-01
  • 1970-01-01
  • 2015-10-10
相关资源
最近更新 更多