The online racing simulator
How to add a xy circle area ?
Hello Programmers,

Im working on a Sumo system and needs help with code for a xy circle
if im in the circle its all ok but if im driving out of it it will specs me.

Ive tryed every combinations from codes but nothing is the right one.

===========================================
My Setups:

Language: C#
Database: MySql
Microsoft Visual C# 2008 Express Version SP1
Libary: LFS_External 1.1.1.4

===========================================





Why do so many people fail on the simplest of problems? *sigh* Oh well...

Ever heard of a² + b² = c² ? You can easily calculate the distance between two points in a X/Y coordinate system by calculating dist = sqrt(Xdist² + Ydist²), where Xdist = Xcirle - Xcar and Ydist = Ycircle - Ycar. With this distance you then only need to check if it's shorter or longer than the circle's radius to determine whether the car is inside the circle or outside.

Just make yourself a Circle class like this...

public class Circle
{
private double x, y, r;

public Circle(double x, double y, double r)
{
this.x = x;
this.y = y;
this.r = r;
}

public bool Contains(double carX, double carY)
{
return Math.Sqrt(Math.Pow(x - carX, 2) + Math.Pow(y - carY, 2)) <= r;
}
}

Then somewhere you define your sumo area and do your checks as required...

Circle sumoArea = new Circle(0, 0, 15 * 65535); //Right in the middle of the map (x=0, y=0) with 15 metres radius
...
if (!sumoArea.Contains(car.X, car.Y))
{ //you lose! }

I haven't tested it, but you get the idea. You can also incorporate automatic conversion of LFS units to metres to make the defining of circle areas a bit more intuitive.
hey thnks for this fast replay you must know i have started coding for 2weeks ^^ but i will learn realy hard that i can code better and faster
Yeah sorry, I didn't want to discourage you or anything. Everybody starts as a newbie at some point I guess...
ja kein problem ^^
habs ja nich gesagt ^^
#6 - sun
Quote from Marco1 :ja kein problem ^^
habs ja nich gesagt ^^

ermm what ? please translate it into english please?
free translation ftw

yes no problem ^^ habs yes nich said ^^
it means:

Yes no problem
i have dont said it.
Yea np
Didnt say it

(i guess more likely didnt say anything but well)

FGED GREDG RDFGDR GSFDG