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

조회 수: 8 (최근 30일)
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!

채택된 답변

Geoff Hayes
Geoff Hayes 2018년 3월 10일
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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by