2017-02-01 3 views
1

イムをプロット:ここillusratedのようにMATLABでほうきのような図を作成しようとしているほうき/光源

Broom plot

私の考えでは、水平線から始め、その後内回転行列を使用していましたループを作成します。しかし、私のコードは私の上でトリックを演奏しているようだ。

一言で言えば、私はそれぞれの行と行の間に同じ角度で特定の点から広がった線を作りたいと思います。

これは、これまでの私のコードです。

th = pi/12; % 15 degrees between every line 
pointA = [20 50]; %The starting point of every line 
pointB = [90 50]; %The ending point of the center line 
v = [pointA(1) pointB(1); pointA(2) pointB(2)]; 
% 
R [email protected](x)[cos(x) -sin(x); sin(x) cos(x)]; % Rotation matrix function 
% 
for i = -4:4 
    c = R(i*th)*v; 
    line([pointA(1) c(1,2)],[pointA(2) c(2,2)]); 
    hold on 
end 

ライン上の角度(中心線を除く)がオフになっている理由はありますか?

答えて

2

回転行列は常に原点([0,0])を中心に回転しますが、それはpointAの周りを回転させたいという問題があります。溶液を

  1. のいずれかが必要角度と長さを有する線を生成し、pointAによってそれらを置換、または
  2. シフト2D空間pointAが原点となるように、回転を行い、バックポイントをシフトであります。

あなたの前回転エンドポイントが自然に定義されているので、私は、簡単な後者の方法を見つけるだろう:

th = pi/12; % 15 degrees between every line 
% pointA and pointB must be column vectors for matrix multiplication later 
pointA = [20; 50]; %The starting point of every line 
pointB = [90; 50]; %The ending point of the center line 
% 
R = @(x)[cos(x) -sin(x); sin(x) cos(x)]; % Rotation matrix function 
% 
hold on; % Hold on and off around loop to plot all lines on same fig 
for i = -4:4 
    % line is initially pointA -> pointB 
    % shift the world by -point A 
    % line is now [0,0] -> pointB-pointA 
    % rotate the world around the origin 
    % line is now [0,0] -> R*(pointB-pointA) 
    % shift the world back 
    % line is now pointA -> R*(pointB-pointA) + pointA 
    c = R(i*th)*(pointB-pointA) + pointA; 
    % note that c is now a single 2d vector: image of pointB 
    line([pointA(1) c(1)],[pointA(2) c(2)]); 
end 
hold off; 
+0

おかげで、@Wolfieを! –

関連する問題