How to generate a dynamic plane of points?
1 view (last 30 days)
Show older comments
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1488122/image.png)
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]?
0 Comments
Accepted Answer
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
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
More Answers (0)
See Also
Categories
Find more on Specifying Target for Graphics Output in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!