delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/03/03/16:04:32

From: "Martin Ambuhl" <mambuhl AT tiac DOT net>
Newsgroups: comp.os.msdos.djgpp,comp.lang.c
Subject: Re: trigonometry problem (math.h)
Date: Tue, 3 Mar 1998 15:48:46 -0500
Organization: Honors Bridge Club
Lines: 66
Message-ID: <6dhqfk$mdi@news-central.tiac.net>
References: <34FC314E DOT A9B3F9D6 AT usa DOT net>
NNTP-Posting-Host: p6.ts2.newyo.ny.tiac.com
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Jesse Meyer wrote in message <34FC314E DOT A9B3F9D6 AT usa DOT net>...
|I am writing some code to determine the vertical velocity of a
|projectile.
|
|The physics equation is voy = x (units/second) * sin(angle)
|
|I want to design a program that will calculate this given the inital
|velocity (x) and the angle.
|
|I am using DJGPP v2.01 and RHIDE 1.4


In almost all implementations there is documentation supplied
either on paper on online.  Since you are using djgpp you can use
the command line
info libc alpha sin
to find out about the sin function.

Now, note that in almost all computer and math contexts,
angles are expressed in radians.  If for some reason you are
using angles in degrees, consider placing something like this
early in your translation unit:
#if !defined(PI)
#define PI 3.14159265358979323846
#endif
#define RADIANS(x) (PI*(x)/180.)

The translation of your equation to C is easy
(remembering to
#include <math.h>
and to link the math library - in djgpp:
gcc -Wall foo.c -o foo.exe -lm
}

double voy(double x, double angle) {
     return  x * sin(angle);
}

or as a macro
#define VOY(x,angle) ((x)*sin(angle))

If your angle is in radians, the call is
  vy = voy(x,angle);

If it is in degrees,
 vy = voy(x,RADIANS(angle));

Easy, no?

The next step is to buy a nice C text -- many have been
recommended here.  Use it.  When you have problems,
check the FAQ for this newsgoup (which you got from
rtfm.mit.edu).  If  you have djgpp-connected problems
check the djgpp FAQ (which you got from the same
place you got djgpp).  If you still have a problem, then
post to comp.lang.c for C questions or to comp.os.msdos.djgpp
for djgpp questions.  It is unusual to have any reason to
crosspost.







- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019