360° = 0° ?

Just starting out? Need help? Post your questions and find answers here.
User avatar
TheAutomator
Enthusiast
Enthusiast
Posts: 112
Joined: Tue Dec 01, 2020 8:33 pm

360° = 0° ?

Post by TheAutomator »

Is the number 360 actually needed if we would code a constantly rotating object?
Or should we stop and turn to '0' when we reach '359' and we add '+1' to it to get a seamless loop?

Simple question that is driving me nuts..
If we talk about 24-h time we also stop at 23:59 before we jump to 00:00 right? :)
User avatar
skywalk
Addict
Addict
Posts: 4210
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: 360° = 0° ?

Post by skywalk »

There are 360° total to traverse a circle. So you increment from 0-359. 360 = 0.
In transmission lines, a frequency(fixed wavelength) can require many wavelengths to complete its journey. Here, the sum of phase travel is important.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
TheAutomator
Enthusiast
Enthusiast
Posts: 112
Joined: Tue Dec 01, 2020 8:33 pm

Re: 360° = 0° ?

Post by TheAutomator »

skywalk wrote:There are 360° total to traverse a circle. So you increment from 0-359. 360 = 0.
In transmission lines, a frequency(fixed wavelength) can require many wavelengths to complete its journey. Here, the sum of phase travel is important.
So in other words, use values 0 to 359, (if we do +1 per frame) and skip 360 because the sprite will be aligned to that angle twice?

repeat
rotation number + 1
if rotation number = 360 then rotation number = 0
rotate sprite(rotation number)
draw sprite
forever


correct?
User avatar
SPH
Enthusiast
Enthusiast
Posts: 561
Joined: Tue Jan 04, 2011 6:21 pm

Re: 360° = 0° ?

Post by SPH »

Code: Select all

angle=360

Debug "Angle : "+Str(angle)+"° ("+Str(angle%360)+"°)"


!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Portable LENOVO ideapad 110-17ACL 64 bits
Version de PB : 6.12LTS - 64 bits
User avatar
TheAutomator
Enthusiast
Enthusiast
Posts: 112
Joined: Tue Dec 01, 2020 8:33 pm

Re: 360° = 0° ?

Post by TheAutomator »

Okay, skip the '360', thanks guys!
Olli
Addict
Addict
Posts: 1194
Joined: Wed May 27, 2020 12:26 pm

Re: 360° = 0° ?

Post by Olli »

360° = 0°

To ease the brain mechanism, if you see a zero digit in the number '360', then you are on 0°.


this difficulty is seen everywhere between theory and apply :

on one hand, the positions where 0° = 360° = 360° × N = 720° = -360° etc... All these equivalent have an even parity.

on the other hand, the domain which excludes at the end if it includes at start : from 0° to 359°.


Positions and domains are two different logics, the position logic depends of the context : mathematical versus physical.

A math position has no 'thickness' : the cursor thickness is null.
But a physical position has a 'thickness'. In example, if you cut a circular surface with a saw : the saw has a thickness, and a security must consider a danger occurs before the 360° are reached.

A domain is a total (here 360°) which starts and finishs, with the idea of a succeding of any same domains. In this way, there are a zero-based defining or a one-based defining.
0-based domain : between 0 included and 360 excluded (=359°)
1-based domain : between 0 excluded and 360 included (very rare using)

Synthesis :
1.a) mathematical position is from 0 to 360
1.b) physical position is from 0 to (360-toolSize)
2.a) 0-based domain is from 0 to 359
2.b) 1-based domain is from 1 to 360

Conclusion : we work usually on the mathematical position logic (from 0° to 360°) and there is 2 functions to modulate :
1) a % b ; integer variables
2) x = mod(x, y) ; floating numbers

/!\ Mod() function is a 'even' math function (and also non-derivable). What it does not interest us in this subject. I add below a small code (procedure OddMod() ) to replace it with a useful function. And I thank the several answers to do the remark. /!\





Note : sum rule

(E = number with even parity
O = number with odd parity)

E + E = E
E + O = O
O + E = O
O + O = E

Parity logic in the sums seems like the sign logic in the products, which causes sometimes confusions.
Last edited by Olli on Mon Feb 01, 2021 4:14 pm, edited 2 times in total.
AZJIO
Addict
Addict
Posts: 2141
Joined: Sun May 14, 2017 1:48 am

Re: 360° = 0° ?

Post by AZJIO »

Code: Select all

f = 0
a = 720
If a >= 360
	f = 1
EndIf
While a >= 360
	a - 360
Wend

Debug "is the circle filled?"
Debug f
Debug "current angle"
Debug a
User avatar
oreopa
Enthusiast
Enthusiast
Posts: 283
Joined: Sat Jun 24, 2006 3:29 am
Location: Edinburgh, Scotland.

Re: 360° = 0° ?

Post by oreopa »

tl;dr ;)

Zero is a DISCREET VALUE. Unique. I like the confusion on faces when I explain that more fully to my non computing friends. It's a very simple concept that a lot of ppl seem to have trouble with :) (not directed at the OP)
Proud supporter of PB! * Musician * C64/6502 Freak
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Re: 360° = 0° ?

Post by djes »

It needs to be well understood as I've seen largely known tools having bad behaviors : Adobe flash for example.

You're talking about rotating objects.
Rotation is a transformation with a start and an end. Needs to define if you rotate your original object or your previous transformed object (1st please).
On computers, rotation is a destructive transformation (sorry). Needs to keep a copy of the original object ( :wink: ).
You can rotate in clockwise direction or anti-clockwise.
Rotation can use floating or integer values (needs to define the lowest possible step).
You can rotate several times with a single operation (needs to define the maximum step).

All theses conditions can't be treated in a single operation. If you want something stable, you'll need to create a procedure to avoid problems.
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: 360° = 0° ?

Post by Michael Vogel »

Just one note for decrementing angle values: I'd prefer constructs like (angle+359)%360 instead of (angle-1)%360 to avoid negative numbers...

...and of course we are talking about degrees all the time, not gradian or radians :wink:
User avatar
TheAutomator
Enthusiast
Enthusiast
Posts: 112
Joined: Tue Dec 01, 2020 8:33 pm

Re: 360° = 0° ?

Post by TheAutomator »

it's interesting how such simple things can be confusing sometimes, i remember programming a timer for my father as a child, scratching my head if i should add the 60'th second each time or not :p

the more I think about the 360 topic the more i see how simple it actually is: 360 would never be reached, the only thing that can be added to 359 is a float less than 1, else we go back to 0.
Olli
Addict
Addict
Posts: 1194
Joined: Wed May 27, 2020 12:26 pm

Re: 360° = 0° ?

Post by Olli »

I tryed to edit my message above, but if I did it, a dated notification of that message would appear. Then I would not be discreet anymore... :D

Code: Select all

; DOUBLE PRECISION FLOATING POINT NUMBER MODULATED (ODD FUNCTION)
Procedure.D OddMod(x.D, y.D)
   If Sign(x) > -1
      ProcedureReturn Mod(x, y)
   Else
      ProcedureReturn y + Mod(x + 1, y) - 1
   EndIf
EndProcedure
Now -1.0° = 359.0° !
(and -0.1° = 359.9°...)

Code: Select all

Debug OddMod(-0.1, 360) ; will display 359.9...
User avatar
TheAutomator
Enthusiast
Enthusiast
Posts: 112
Joined: Tue Dec 01, 2020 8:33 pm

Re: 360° = 0° ?

Post by TheAutomator »

Olli wrote:I tryed to edit my message above, but if I did it, a dated notification of that message would appear. Then I would not be discreet anymore... :D
; DOUBLE PRECISION FLOATING POINT NUMBER MODULATED (ODD FUNCTION
hah, you didn't need to do that but thanks for showing :D
Olli
Addict
Addict
Posts: 1194
Joined: Wed May 27, 2020 12:26 pm

Re: 360° = 0° ?

Post by Olli »

Uh... Imagine you have any very large pieces to rotate : one degree could be too much !
User avatar
TheAutomator
Enthusiast
Enthusiast
Posts: 112
Joined: Tue Dec 01, 2020 8:33 pm

Re: 360° = 0° ?

Post by TheAutomator »

Olli wrote:Uh... Imagine you have any very large pieces to rotate : one degree could be too much !
That's why i was talking about floats somewhere in my previous answer :)
Post Reply