Draw an angled line, with a slope relative to a reference point.

Version 1.1.0.0 (1.73 KB) by Elad
Draw a line at an angle in degrees which goes through a reference point inputted as an argument.
1.3K Downloads
Updated 2 Oct 2009

View License

function [yline xline] = drawslope(I, alpha, refpoint)
%
% function to draw a line at a desired angle <alpha>,
% which goes through a reference point <refpoint>
% function inputs:
% <I>: Image for which the drawing is desired.
% Range:3Dim, grayscale, or logical
% <alpha>: Angle in degrees, where 0 is complete
% horizontal
% Range: -Inf - +Inf (cyclic after +
% (-) 180 degrees of course)
% <refpoint> : Reference interception point with the slope
% Range: A varaible of size 2x1, where
% refpoint(1) is horizontal and (2) is vertical
% function outputs:
% <yline> : Y axis coordinates of both line ends
% <xline>: X axis coordinates of both line ends
%
% outputs should be used with plot
% function as following:
% plot(yline,xline,...plot specifiers)
%
% Example usage:
% Image = imread('someImage');
% image_centroid = [100 240];
% [yline xline] = drawslope(Image, -60, image_centroid);
% imshow(Image);
% hold on;
% plot(yline, xline, 'blue','LineWidth',2);
%
%
% Written by Elad Boneh, 15.8.2009
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Cite As

Elad (2024). Draw an angled line, with a slope relative to a reference point. (https://www.mathworks.com/matlabcentral/fileexchange/25370-draw-an-angled-line-with-a-slope-relative-to-a-reference-point), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R13
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes
1.1.0.0

Description.

1.0.0.0