how to define a clockwise or counterclockwise angular vector based on a direction at the initial angular position?

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!

 Accepted Answer

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 Comments

I appreciate the hints! However I am still confused about how to take directional vector into account. Here is the picture of my situation.
The direction I was referring to can be interpreted as the derivative of the circle at 0 degree (initial position). The red arrow represented a direction of [0,1] (pointing in the positive y-direction), and the angle will approach 90 degree in that direction such as [0,10,20...90], and yellow arrow is the other direction. However, the input directional vector can be on any point on the circle, so it cannot be always be classified as positive or negative 1, such as the following
The initial position is 130 degree, and given the red arrow, which is represented as [-sind(130),cosd(130)], I want to generate a vector such as [130,140...350,0,10,...80,90].
Rest assured this is not a homework question, but I do appreciate hints because it helps me to learn better. Thank you for your time!
You could try
mod(initialAngle:direction * 10:direction * ...
mod(direction * finalAngle, 360), 360)
though that may still not be what you want...

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!