How to generate a dynamic plane of points?

5 views (last 30 days)
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]?

Accepted Answer

VINAYAK LUHA
VINAYAK LUHA on 20 Sep 2023
Edited: VINAYAK LUHA on 21 Sep 2023
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 Comments
Estel
Estel on 20 Sep 2023
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 on 21 Sep 2023
Edited: VINAYAK LUHA on 21 Sep 2023
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

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB Coder in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!