File Exchange

image thumbnail

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

version 1.2.2 (11.5 KB) by J. Benjamin Kacerovsky
Draws 3 arrows representing the basis vectors of an R3 coordinate system

16 Downloads

Updated 02 Jun 2020

GitHub view license on GitHub

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

Cite As

J. Benjamin Kacerovsky (2020). drawVector- draws 2D or 3D vectors from specified points (https://www.github.com/JBKacerovsky/matlabSnippets), GitHub. Retrieved .

Comments and Ratings (0)

Updates

1.2.2

fixed description

1.2.1

connected to gitHub

1.2.0

added drawOrdinates

MATLAB Release Compatibility
Created with R2019b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Tags Add Tags