delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/03/16/15:50:48

Message-ID: <36EE8469.14ED8663@bellsouth.net>
From: Lester Davis <ringo1 AT bellsouth DOT net>
X-Mailer: Mozilla 4.04 [en] (Win95; I)
MIME-Version: 1.0
Newsgroups: comp.os.msdos.djgpp
Subject: Trig Help real code
References: <36EE71C9 DOT 6A160A75 AT bellsouth DOT net>
Lines: 47
Date: Tue, 16 Mar 1999 16:18:39 GMT
NNTP-Posting-Host: host-209-214-65-22.atl.bellsouth.net
NNTP-Posting-Date: Tue, 16 Mar 1999 11:18:39 EST
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

In case it was not clear here is the acutal code I'm tying to display the
results with. Right now I just want a swwep from 5 to 85 degrees, If I can
get this to work the second qudrant shouldn't be that hard.
Thanks
Ringo



// Sonarplt  Sonar Plot for mapping a room
// to compile gcc sonarplt.c -lalleg -lm
#include <conio.h>    // For the getch() function.
#include <stdio.h>
#include "allegro.h"
#include <math.h>
#include <dos.h>
#define cone 10

void Plot_beam(int angle,int range,int conew,int color);

int main()
{
 //screen is 640 W 480 H

 int angle;
 int range;

 allegro_init();
 set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0);
 clear(screen);

while(!kbhit())
  {
   textout(screen, font, "Sonar Ranging demo", 280, 470, 2);
   line(screen, 1,240,  630,240,  15);
   circle(screen, 320,240,10, 15);
   range=200;
   for(angle=5;angle<85;angle=angle+5)
     {
      Plot_beam(angle,range,cone,15);
      Plot_beam(angle,range,cone,255);
     }
  }
allegro_exit();
return 0;
}

void
Plot_beam(int angle,int range,int conew,int color)
{
int temprange=0;
double x1,x2,y1,y2;
int xa,xb,ya,yb;
int posangle,negangle;

for(temprange=15;temprange<range;temprange=temprange+15)
   {
    delay(100);
    posangle=angle+(conew/2);
    negangle=angle-(conew/2);
    x1=temprange*cos(posangle); /* get x & y Co-ords */
    y1=temprange*sin(posangle);
    x2=temprange*cos(negangle);
    y2=temprange*sin(negangle);
    xa=abs((int)x1);           /* change to ints and get abs */
    xb=abs((int)x2);          /* abs is to set to first quadrant */
    ya=abs((int)y1);
    yb=abs((int)y2);
    xa=320+xa;                 /* make origin center of screen*/
    xb=320+xb;
    ya=240-ya;
    yb=240-yb;
    line(screen, xa,ya,  xb,yb,  color); /* draw the lines*/
   }
}/* end of Plot beam

- Raw text -


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