Project

General

Profile

Revision 1054

Added by Nico Paris about 15 years ago

Added file to check for collisions with circles

View differences:

branches/simulator/projects/simulator/rayHits.c
1
#include <stdlib.h>
2
#include <math.h>
3

  
4
double Xr, Yr, Tr, Xc, Yc, Rc; // (X,Y,theta for ray) (X,Y,radius for circle)
5

  
6
boolean rayHits(double Xr,double Yr,double Tr,double Xc,double Yc,double Rc)
7
{
8
	double m, b, D;
9
	m = tan(Tr);
10
	b= -m * Xr + Yr;
11
	D = (abs(Yc - m * Xc - b)) / (sqrt(m * m + 1);
12

  
13
	if (D < Rc )
14
	{
15
		return true;
16
	}
17
	else
18
	{
19
		return false;
20
	}
21

  
22
	return false;
23
}

Also available in: Unified diff