tsounakis

vector

Oct 28th, 2022
1,027
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.79 KB | None | 0 0
  1. classdef vector
  2. properties
  3.     Head
  4.     Tail
  5.     Type
  6.     Angle
  7.     Length
  8.     Name
  9. end
  10.     methods
  11.         function vplot(obj)
  12.             dp = obj.Head - obj.Tail;
  13.             q = quiver(obj.Tail(1), obj.Tail(2), ...
  14.                 dp(1), dp(2), 0, '.', ...
  15.                 'linewidth', 1);
  16.             if obj.Type == 'Voltage'
  17.                 q.Color = 'red';
  18.             else
  19.                 q.Color = 'blue';
  20.             end
  21.             mid = (obj.Tail(:) + obj.Head(:)*2).'/2;
  22.             text(mid(1)+15, mid(2), obj.Name)
  23.             hold on
  24.             grid on
  25.         end
  26.         function q = setHead(obj)
  27.             q = [sin(deg2rad(obj.Angle))*obj.Length + obj.Tail(1); cos(deg2rad ...
  28.                 (obj.Angle))*obj.Length + obj.Tail(2)];
  29.         end
  30.     end
  31. end
Advertisement
Add Comment
Please, Sign In to add comment