Filter löschen
Filter löschen

Draw a line with an angle

132 Ansichten (letzte 30 Tage)
SUBHA GHOSH
SUBHA GHOSH am 30 Jun. 2017
Bearbeitet: Garvit Amipara am 8 Apr. 2021
we have a point(x,y) and length of the line is L and the angle between horizontal line and the draw line is A.
  2 Kommentare
Jan
Jan am 30 Jun. 2017
Fine. What is your question? What have you tried so far and which problem occurres?
Image Analyst
Image Analyst am 30 Jun. 2017
There is a line function you know. Just specify the two endpoints, which can be computed from simple trig.
line([x1,x2], [y1,y2], 'Color', 'r', 'LineWidth', 2);

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Ahmed raafat
Ahmed raafat am 29 Jul. 2017
%L is the length
%angle is alpha
x2=x+(L*cos(alpha));
y2=y+(L*sin(alpha));
plot([x x2],[y y2])
  1 Kommentar
Garvit Amipara
Garvit Amipara am 8 Apr. 2021
Bearbeitet: Garvit Amipara am 8 Apr. 2021
This works perfectly!
Note: instead of sin(alpha), cos(alpha), use sind(alpha) and cosd(alpha) to avoid the floating point errors of the sin and cos values.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by