Last active
October 8, 2016 22:28
-
-
Save infusion/0112864ba12803d1909a to your computer and use it in GitHub Desktop.
Matlab Drawing Helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% Draws a point at the intersection of two lines | |
% L1 = V1 + s * W1 | |
% L2 = V2 + t * W2 | |
function drawAtLineIntersection(V1, W1, V2, W2) | |
if isequal(V1, V2) && isequal(W1, W2) | |
c = V1; % could be any point on the line | |
else | |
i = [W1, -W2] \ (V2 - V1); | |
c = V1 + i(1) * W1; | |
end | |
plot(c(1), c(2), 'b*'); | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% Draws a circle with radius r at point p | |
function drawCircle(p, r) | |
phi = linspace(0, 2 * pi, 1000); | |
plot(p(1) + r * cos(phi), p(2) + r * sin(phi)); | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% Draws a line between point p1 and p2 | |
function drawLine(p1, p2) | |
plot([p1(1), p2(1)], [p1(2), p2(2)]); | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% Draws a line between point p1 and p2 in 3D | |
function drawLine3(p1, p2) | |
plot3([p1(1), p2(1)], [p1(2), p2(2)], [p1(3), p2(3)]); | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% Draws two circles which are connected by a line | |
function drawLineEndpoint(p1, p2, r1, r2) | |
n = (p2 - p1) / norm(p2 - p1); | |
drawCircle(p1, r1); | |
hold on | |
drawCircle(p2, r2); | |
drawLine(p1 + n * r1, p2 - n * r2); | |
hold off | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment