drawVector- draws 2D or 3D vectors from specified points

Draws 3 arrows representing the basis vectors of an R3 coordinate system
566.0 次下载
更新时间 2021/6/22
drawVector - draws 2D or 3D vectors from specified points
drawOrdinates - draws 3 arrows representing the basis vectors of an R3 coordinate system
----------------------------------
drawVector - is a very simple function to make drawing vectors using the
quiver and quiver3 functions a little more convenient
all this is to prepare the input from xyz triplets or lists of pints and
vectors and pass it into the quiver or quiver3 functions
I was just getting tired of typing it out every time
Syntax:
q=drawVector(points, vectors);
q=drawVector(points, vectors, color);
q=drawVector(points, vectors, color, weigth);
drawVector(points, vectors);
drawVector(points, vectors, color);
drawVector(points, vectors, color, weigth);
Inputs:
points - Nx3 (3D) or Nx2 (2D) matrix; rows correspond to points
if N==1 the same point will be used as origin for all vectors
vectors - Nx3 (3D) or Nx2 (2D) matrix; rows correspond to vectors
color - (optional) string ('r', 'red', etc), RGB triplet or
hexadecimal string; default='red
weight - (optional) scalar setting LineWidth and arrow head size; default=3;
Outputs:
for simple drawing the output does not have to be defined
defining the output, p, saves the graphics element to allow later editing
Example:
% draw 3 red vector arrows from 3 points
% red is the default color
p=[0 0 0; 0 1 1; 2 1 1];
v=[1 1 1; 2 3 -4; 1 0 0];
drawVector(p, v);
axis equal
% draw 3 blue vector arrows from a single point with wider lines
p=[2 1 1];
v=[1 1 1; 2 -3 -1; 1 0 0];
drawVector(p, v, 'blue', 5);
axis equal
% defining the output saves the graphics element and allows for later
% changes to quiver properties
p=[2 1 1];
v=[1 1 1; 2 -3 -1; 1 0 0];
q=drawVector(p, v, 'blue', 5);
axis equal
q.LineStyle='-.';
-----------------------------
drawOrdinates - simple function to draw arrows representing the basis
vectors of any R3 coordinate system
Syntax: drawOrdinates
drawOrdinates(ord, ori)
drawOrdinates(ord, ori, ...)
this is a simple function to draw 3 vectors representing the axes of a
coordinate system
All this really does is prepare the inputs to pass them into the built-in
quiver3 function. I was just tired of typing it out all the time.
Inputs:
ord - ordinates; 3x3 matrix, each column represents one axis as a 1x3
vector. default x, y, z unit vectors at the origin ([1, 0, 0; 0, 1, 0; 0, 0, 1])
ori - origin; 1x3 matrix specifing the coordinates at which to draw;
default [0, 0, 0]
Optional Name-Value pairs
scale - scalar; factor by which to scale the length of each arrow;
default=0
weight - scalar; defines lineweight and arrow head size; default=3
colors - 1x3 list of strings defining colors for each vector;
default=['r', 'b', 'g']);
alternative: 3x3 matrix, where each row defienes one arrow color as
an RGB triplet
Outputs:
no outputs need to be specified
Example 1:
% calling the function without specifying any input will draw 3 unit
% vectors along the x, y, and z axis at the origin
drawOrdinates
Example 2:
% vec=[3, 4, 5]; % start with a random vector
% vec=vec/norm(vec); % normalize
% ord=null(vec); % use null(x) to find 2 orthonormal vectors
% ord=horzcat(vec', ord); % concatenate matrix of orthonormal basis vectors
%
% % draw new ordinates with default settinngs at the origin
% drawOrdinates(ord);
% axis equal
%
% % draw new ordinates centered at [2, 10, 3] with a changed appearence
% drawOrdinates(ord, [2, 10, 3], 'weight', 5, 'scale', 5, 'colors', [0 0 1; 0 0 1; 0 0 1]);
% axis equal

引用格式

J. Benjamin Kacerovsky (2024). drawVector- draws 2D or 3D vectors from specified points (https://github.com/JBKacerovsky/Draw_Vector), GitHub. 检索来源 .

MATLAB 版本兼容性
创建方式 R2019b
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Vector Fields 的更多信息
标签 添加标签

Community Treasure Hunt

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

Start Hunting!

无法下载基于 GitHub 默认分支的版本

版本 已发布 发行说明
1.2.3

separated DrawVector functions from the usefulSnippets collection

1.2.2

fixed description

1.2.1

connected to gitHub

1.2.0

added drawOrdinates

1.0.0

要查看或报告此来自 GitHub 的附加功能中的问题,请访问其 GitHub 仓库
要查看或报告此来自 GitHub 的附加功能中的问题,请访问其 GitHub 仓库