Gamestudio Links
Zorro Links
Newest Posts
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Help with plotting multiple ZigZag
by M_D. 04/26/24 20:03
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (AndrewAMD, exile, Ayumi), 836 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
degree mod 180° #442875
07/05/14 10:20
07/05/14 10:20
Joined: Jul 2001
Posts: 6,904
H
HeelX Offline OP
Senior Expert
HeelX  Offline OP
Senior Expert
H

Joined: Jul 2001
Posts: 6,904
Hi all,
I have written the following Lite-C function to shift a degree as a double value between -180° ... 0° ... +180°. The outcome is the same as the ang() function, but it works different: instead of repeatedly adding or subtracting a multiple of 360 degrees, I use the fmod function (which implements that maybe anyway, I don't know):

Code:
// clamps a floating point degree between -180° ... 0° ... +180°
double avAngleDegreeMod180(double angleDegree) {
   if (angleDegree > 180) {
      double remainder = fmod(angleDegree, 360);
      if (remainder > 180) {
         return -180 + (remainder - 180);
      } else {
         return remainder;
      }
   } else {
      if (angleDegree >= -180) {
         return angleDegree;
      } else {
         return -avAngleDegreeMod180(-angleDegree);
      }
   }
}


Can anyone think of a faster/more elegant solution? This feels somehow bloated... eek

Re: degree mod 180° [Re: HeelX] #442877
07/05/14 10:35
07/05/14 10:35
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Code:
var my_ang(var x)
{
	x = x%360;
	x = (x+360)%360;
	if(x > 180) return x-360;
	
	return x;
}

void main()
{
	fps_max = 60;
	while(1)
	{
		var i = 540*sinv(total_ticks*2);
		DEBUG_VAR((int)i,20);
		DEBUG_VAR((int)my_ang(i),40);
		DEBUG_VAR((int)ang(i),60);
		wait(1);
	}
}



I don't know if you like that approach more than yours, probably not.


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: degree mod 180° [Re: Superku] #442878
07/05/14 10:41
07/05/14 10:41
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline
Expert
Kartoffel  Offline
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Not sure if I understood what you're trying to do, but:
(x + 180) % 360 - 180
confused


POTATO-MAN saves the day! - Random
Re: degree mod 180° [Re: Kartoffel] #442889
07/05/14 12:02
07/05/14 12:02
Joined: Jul 2001
Posts: 6,904
H
HeelX Offline OP
Senior Expert
HeelX  Offline OP
Senior Expert
H

Joined: Jul 2001
Posts: 6,904
Problem is, that I do not want to use fixed point arithmetics to get highest precision wink


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1