How to generate a dynamic plane of points?

조회 수: 3 (최근 30일)
Estel
Estel 2023년 9월 20일
편집: VINAYAK LUHA 2023년 9월 21일
I need to generate a dynamic plane of points perpendicular to a given input vector.
For example, if given input vector of [0 0 1], I want to generate a set of points that are uniformly distributed and perpendicular to the input vector, similar to this:
As an output, I get a list of coordinates for each point in the array -- see the attached .mat file for an example.
For an input vector such as the above example, this is a very straightforward process and I had this working very quickly. The issue is when the vector is complex and not parallel to an axis. How can I automatically generate these points when given a more complicated vector such as [1 2 0] or [-5 3 2]?

채택된 답변

VINAYAK LUHA
VINAYAK LUHA 2023년 9월 20일
편집: VINAYAK LUHA 2023년 9월 21일
Hi Estel,
It is my understanding that you wish to find grid points on a plane perpendicular to a given input vector.
Here's a workaround -
% Input vector
inputVector = [1 1 1];
% Normalize the input vector
inputVector = inputVector / norm(inputVector);
% Find two orthogonal vectors perpendicular to the input vector using dot
% and cross products
if inputVector(1) ~= 0 || inputVector(2) ~= 0
orthogonalVector1 = [inputVector(2) -inputVector(1) 0];
else
orthogonalVector1 = [0 1 0];
end
orthogonalVector2 = cross(inputVector, orthogonalVector1);
% Define grid parameters
gridSize = 10;
gridSpacing = 1;
% Generate grid points in a rectangular pattern
[X, Y] = meshgrid(-gridSize/2 : gridSize/2, -gridSize/2 : gridSize/2);
gridPoints = [X(:), Y(:)];
% Transform grid points to be perpendicular to the input vector
gridPointsPerpendicular = gridPoints(:, 1) * orthogonalVector1 + gridPoints(:, 2) * orthogonalVector2;
% Calculate the center of the grid
center = [mean(gridPointsPerpendicular(:, 1)), mean(gridPointsPerpendicular(:, 2)), mean(gridPointsPerpendicular(:, 3))];
% Display the grid points and the input vector arrow
figure;
hold on;
scatter3(gridPointsPerpendicular(:, 1), gridPointsPerpendicular(:, 2), gridPointsPerpendicular(:, 3), 'filled');
quiver3(center(1), center(2), center(3), inputVector(1), inputVector(2), inputVector(3), 'r', 'LineWidth', 2);
hold off;
xlabel("x")
ylabel("y")
zlabel("z")
axis equal;
Hope this helps.
  댓글 수: 2
Estel
Estel 2023년 9월 20일
Thank you very much!
As a quick follow-up: what is the purpose of the "gridSpacing" variable? I don't see it used anywhere after you initially set a value.
VINAYAK LUHA
VINAYAK LUHA 2023년 9월 21일
편집: VINAYAK LUHA 2023년 9월 21일
Hi Estel,
I initially thought to include a functionality to specify the degree of sparseness of the grid, however later I felt it may go out of the scope of the question and left that on you to explore and implement if needed.
Thanks

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Discrete Data Plots에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by