Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / c++ equivalent to sin and cos

Author
Message
david w
18
Years of Service
User Offline
Joined: 18th Dec 2005
Location: U.S.A. Michigan
Posted: 4th Apr 2008 21:36
Im not really a C++ master so I'm kinda learning as Im going. I am trying to convert this:



To C++ without using GDK sin and cos functions. I want to just use C++ functions. What is the equivalent to sin/cos in C++ and what are the header files I need to include. Thank you.
dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 4th Apr 2008 21:41
#include "math.h"

And you can then use sin()/cos() and many other functions and constants, remember they all use radians unlike DBP/GDK's degrees.

david w
18
Years of Service
User Offline
Joined: 18th Dec 2005
Location: U.S.A. Michigan
Posted: 4th Apr 2008 21:44
Thank you.
Scottie Dog
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location:
Posted: 4th Apr 2008 22:34
If your using GDK you could also use their version of it...

dbCOS() and dbSIN()

I haven't done any testing to see which is the faster though.
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 4th Apr 2008 22:43
Quote: "remember they all use radians unlike DBP/GDK's degrees."


Only a mathematician would have insisted on that for any programming language. Common usage is seldom in radians except in the lab or the classroom. They should have provided a #pragma to specify the base.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 4th Apr 2008 22:50 Edited at: 4th Apr 2008 22:55
Quote: "They should have provided a #pragma to specify the base."

It's processor design; the instructions themselves use radians. Creating a macro to convert between radians and degrees isn't a difficult task anyway.



Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 4th Apr 2008 22:58
Quote: "Only a mathematician would have insisted on that for any programming language."


A computer specialist would do it too. Just think about the McLauren and Taylor series which won't work if you use degrees...
Ofcourse the current method is more efficient and more complicated, but the idea should be the same.

It's the programmer's life:
Have a problem, solve the problem, and have a new problem to solve.
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 4th Apr 2008 23:50 Edited at: 4th Apr 2008 23:51
@Benjamin

True. But what would it take for them to convert from degrees to radian for the benefit of the programmer? Were the processor instructions similarly constrained when the C language was first developed?

@Sven B

I can see the argument but what units are used most often? At a guess I'd say engineers, who are likely to be more plentiful than mathematicians, and now game developers and hobbyists get the most use out programming languages.

Not arguing, mind you. I'll go through the steps as necessary. But two things bug me. One is my need (OK, want) for speed where the extra conversion rankles me. The other is that I do this kind of thing infrequently enough that I have to look up the relationship again, due to my aging memory, but often enough that it bothers me that I can't remember. And I can never find that

#define radians(degrees)

macro that came in so handy twenty years ago.

The problem is that it's hard to think in terms of radians because they're really pretty large units or chunks out of a full circle, something close to 57 degrees if I remember right. A couple of weeks ago I started a small utility project for drawing not only full circles but also arcs using GDK, mostly for one purpose I have at hand that requires that I use floating point radii instead of integers.

My first inclination was just to plot x/y points from 0 to 360 degrees. Gawd, did that leave gaps in the circle. Imagine taking that approach using radians. Just how fine would you need to increment your angle to get all the gaps filled and how large a radius? Okay, so that approach didn't work out whether it was in degrees or radians. But it was much easier to approach it from incremental degrees rather than small pieces of big radians.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
david w
18
Years of Service
User Offline
Joined: 18th Dec 2005
Location: U.S.A. Michigan
Posted: 5th Apr 2008 06:47
ok so this is more complicated than I thought. So does anyone have some code that they can share that will accomplish radians to degrees. It would be rather helpful to be able to just put in a degree and have it just work.
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 5th Apr 2008 07:02
1 radian = 57.2958 degrees if you want to use pure numbers and not directly involve pi. So

degrees = radians * 57.2958

and

radians = degrees/57.2958

The rest depends on whether you're using the db functions or code classic.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
david w
18
Years of Service
User Offline
Joined: 18th Dec 2005
Location: U.S.A. Michigan
Posted: 5th Apr 2008 07:24 Edited at: 5th Apr 2008 07:25
I am not using anything that is DB or GDK I am using pure Dx9.0 and Ageia. I dont even use DB or GDK unless I am prototyping.


Thank you for the help.

Login to post a reply

Server time is: 2024-11-20 07:23:29
Your offset time is: 2024-11-20 07:23:29