Effacer les filtres
Effacer les filtres

Draw a straight line from the center (0,0) 25 degrees in the coordinate system

3 vues (au cours des 30 derniers jours)
Saud
Saud le 3 Avr 2024
Commenté : Harald le 8 Avr 2024
I don't have any experience in Matlab but I need to measure distances for a simulation. I ask for your support. From the center of the coordinate system (0,0) I have to draw a straight line that is 4m long as an orientation. Then a straight line from the left side that starts at the point (-1.0), 25 degrees from the center line and ends at the end of the 4m straight. So also from the right side a straight line with the beginning (1.0) and also ends at 4m.
I have to move the starting points (-1.0) and (1.0) after each measurement of the distance of the line from its starting points for the next measurement. For example: the next starting points of the two lines from the left and right start at (-2.0) and (2.0).
I have an example in the appendix.
And then, finally, for each angle from 0 degrees to 25 degrees from the center (0.0), perform the displacements on the X-axis. For example, starting with (-1.0) and (1.0) to (-5.0) and (5.0) I will upload example in the attachment.
Thank you in advance!

Réponses (1)

Harald
Harald le 5 Avr 2024
Hi,
I suppose you are fine calculating start and end points of each line?
plot([x1, x2], [y1, y2])
will draw a line from (x1, y1) to (x2, y2). When using multiple plot commands, make appropriate use of the hold command.
To familiarize yourself with MATLAB, consider taking the free MATLAB Onramp.
Best wishes,
Harald
  2 commentaires
Saud
Saud le 6 Avr 2024
Thank you for the feedback. How to draw a line at a certain angle from the zero point?
Harald
Harald le 8 Avr 2024
Hi,
in my suggestion, use
x1 = 0;
y1 = 0;
x2 = cosd(theta) * d;
y2 = sind(theta) * d;
If different scaling is used on the axes, the angle may look incorrect. To prevent that, use
axis equal
Best wishes,
Harald

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by