フィルターのクリア

How to plot a point, if it lies within a cube?

6 ビュー (過去 30 日間)
Shiv Karpoor
Shiv Karpoor 2022 年 2 月 3 日
コメント済み: Shiv Karpoor 2022 年 2 月 3 日
Hello MATLAB Community,
Say I have a point 'A' whose coordinates are [116, 6.63, 22].
Now I want create a boundary cube whose center of origin is (0,0,0) and the cube must be from -150 to +150 in X,Y,Z direction.
I would only like to plot the point A, if it is within the boundary condition (-150 to +150).
My question is how do you create a boundary cube and tell matlab to plot the point, only if its within the boundary limit?
I was not able to create a boundary for this problem.
Can anyone please help me with any suggestions.
Thank you in advance!!
I really appreciate your help.
Kind regards,
Shiv

採用された回答

David Hill
David Hill 2022 年 2 月 3 日
a = -pi : pi/2 : pi;
ph = pi/4;
ampl=150;
x = ampl*[cos(a+ph); cos(a+ph)]/cos(ph);
y = ampl*[sin(a+ph); sin(a+ph)]/sin(ph);
z = ampl*[-ones(size(a)); ones(size(a))];
figure
surf(x, y, z, 'FaceColor','g','FaceAlpha',0.1)
hold on
grid on
A=[116, 6.63, 22];
if all(abs(A)<=ampl)
plot3(A(1),A(2),A(3),'o','Color','b','MarkerSize',5,'MarkerFaceColor','b');
end
  1 件のコメント
Shiv Karpoor
Shiv Karpoor 2022 年 2 月 3 日
Hi David Hill,
Thank you for the solution of the example.
I was expecting something of this solution for my script.
I really appreciate your help!!

サインインしてコメントする。

その他の回答 (1 件)

Fangjun Jiang
Fangjun Jiang 2022 年 2 月 3 日
For boundary, use plot3() to plot the lines between the 8 tip points of the cube.
To check if a point is within the boundary, you just need to check if all the coordinates (x,y,z) are within the range of [-150, 150]
  1 件のコメント
Shiv Karpoor
Shiv Karpoor 2022 年 2 月 3 日
Hi Fangjun Jiang, I don't want to manully cross check it. hence I mentioned if statement in the question, Thank you for your response.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by