how to define a clockwise or counterclockwise angular vector based on a direction at the initial angular position?
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Let's say I have a circle at (0,0) with radius = 1; I want the computer to generate a equally spaced vector from 0 degree to 90 degree based on a direction specified at 0 degree. For example, if the direction is [0,1], it will be a counterclockwise rotation such as [0,10,20,30...80,90]; if the direction is [0,-1], it will be a clockwise rotation such as [0,350,340,330...100,90].
The direction, initial and final angular positions are all inputs, and I want the computer to self determine which way the rotation will occur.
I am new to Matlab, thanks a lot for the help!
0 commentaires
Réponse acceptée
Geoff Hayes
le 10 Mar 2018
Yizhou - this almost seems like a homework question so we can only give out hints. Let's assume then that you have three inputs
initialAngle % degrees i.e. 0
finalAngle % degrees i.e. 90
direction % +1 or -1
angleStepSize % degrees i.e. 10
(I know that you have said that a positive direction is a counter-clockwise rotation but to me that seems off. A counter-clockwise rotation around the axes starting at zero degrees seems (to me) that we would go negative: 0, 350, 340, etc. if our step size is ten degrees.)
We can easily create an array of angles from 0 to 90 with a step size of ten as
initialAngle = 0;
finalAngle = 90;
angleStepSize = 10;
direction = 1;
angles = initialAngle:direction*angleStepSize:direction*finalAngle
which gives us
angles =
0 10 20 30 40 50 60 70 80 90
If we switch the direction to be negative one, then we would get
angles =
0 -10 -20 -30 -40 -50 -60 -70 -80 -90
which isn't what you want but you can see how we create an array in the "other" direction. We could then use mod to get something a little closer to what you want
direction = -1
angles = mod(initialAngle:direction*angleStepSize:direction*finalAngle, 360)
where
angles =
0 350 340 330 320 310 300 290 280 270
The next step (which will be left to you) is how to figure out the final angle so that we (in this case) get an array like 0, 350, 340, ..., 90
4 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

