2017-07-06 11 views
0

私は、ディスクの位置と法線のみを使って3D空間で2Dディスクのリングに沿って点を生成しようとしていました。数学 - 3D空間で回転した2Dディスクの生成点

私はポイントを生成するために以下のコードを使用してきましたが、Matlabでテストしていますが(ポイントは正しく生成されていることを確認するためにこのコードを使用します)正しく

numPoints = 25; 
radius = 1; 
pos = [1; 2; 3]; 
dir = normc([3; 4; 6]); % normalised 

function [pointsT, points] = GenerateDiscPoints(numPoints, radius, pos, dir) 
    points = zeros(numPoints, 3); 
    pointsT = zeros(numPoints, 3); 

    % Angle between points 
    angle = 2 * pi/numPoints; 

    for i = 1:numPoints+1 
     % Current point angle 
     theta = angle * i; 

     % Generate point in flat disc (y is vertical axis in Unity) 
     x = radius * cos(theta) + pos(1); 
     y = 0 + pos(2); 
     z = radius * sin(theta) + pos(3); 

     % Save points 
     points(i, 1) = x; 
     points(i, 2) = y; 
     points(i, 3) = z; 

     % Calculate t value to translate points 
     t = (dir(1) * pos(1) - dir(1) * x + dir(2) * pos(2) - dir(2) * y + dir(3) * pos(3) - dir(3) * z)/(dir(1)*dir(1) + dir(2)*dir(2) + dir(3)*dir(3)); 

     % Translate points to correct location 
     xT = x + t*dir(1); 
     yT = y + t*dir(2); 
     zT = z + t*dir(3); 

     % Save translated points 
     pointsT(i, 1) = xT; 
     pointsT(i, 2) = yT; 
     pointsT(i, 3) = zT; 
    end 

    % Plot 
    figure; 
    hold all; 
    grid on; 
    scatter3(points(:,1), points(:,2), points(:,3), 25, 'r'); 
    scatter3(pointsT(:,1), pointsT(:,2), pointsT(:,3), 25, 'g'); 
    p3 = line([pos(1) pos(1)+dir(1)], [pos(2) pos(2)+dir(2)], [pos(3) pos(3)+dir(3)]); 
    set(p3, 'Color', 'blue'); 
end 

Here's a picture of the output.

青い線は、ディスクの正常で、赤い点が翻訳される前のポイントであり、緑色の点は、変換された後の点です。私の目では、翻訳されたポイントは、通常指定されているディスクには生成されていないようです。

現在のアルゴリズムで何が問題になっていますか?これを行うためのよりよい方法は何でしょうか?

+0

[MATLABで平面の法線ベクトルをプロット]の可能な重複(https://stackoverflow.com/questions/35082373/plotting-a-normal-vector-to-a-plane- in-matlab) – dasdingonesin

+0

あなたの軸スケーリングはそれを間違って見せます。 ['axis equal']を使用してください(https://de.mathworks.com/help/matlab/ref/axis.html#inputarg_style) – dasdingonesin

+0

私は軸が等しいかどうか分かりませんでした。それを使って、グラフが正しいように見えましたが、@ uggが正しいものと信じています。私のコードは点の投影を生成するだけなので、円ではなく楕円を生成します。 –

答えて

1

dirの方向に沿った単純な線形変換が不十分である - あなたは、すなわち楕円、通常dirposにおける平面上の円の投影になってしまいます。

次のいずれかの可能性:

又は

  • pos直交基底を構築しますdir。理想的abs(dot(dir, X)) < 0.8(両方とも正規化されていると仮定すると)んので、彼らは

  • お互いに近すぎではありません - X軸は dirに平行である場合

    1. チェック:これを行うには

      簡単な方法

    2. (1)が真の場合はdir2 = Y、そうでない場合はdir2 = Xとします。

    3. A = normalize(cross(dir, dir2))を作成するには、次のように入力します。

    4. B = cross(dir, A)を作成します。

    5. thetaの各値でポイントを生成することができます。これはpos + radius * (A * cos(theta) + B * sin(theta))(ベクトル表記)です。

+0

半径の値を変えたいのであれば、 'pos + A * radius * cos(theta)+ B * radius * sin(theta)'になるでしょう? –

+0

@bradleygrayはい申し訳ありませんが、私はそれを置くのを忘れていました – meowgoesthedog

関連する問題