SRL Archive - SRL Suggestions

WhichQuadrant


TRiLeZ

2009-12-03 19:24:33


{*******************************************************************************
function WhichRSQuadrant(x, y, OriginX, OriginY: Extended): Integer;
By: TRiLeZ
Description: Results the Quadrant in which a point is in. The first quadrant
is the top-right quadrant, which then increases in a clockwise order.
If the point is at the origin or between 2 quadrants, the result will be 0.
*******************************************************************************}
function WhichRSQuadrant(x, y, OriginX, OriginY: Extended): Integer;
begin
Result := 0;
if (x < OriginX) and (y < OriginY) then Result := 4 //Top-left Quadrant
else
if (x > OriginX) and (y < OriginY) then Result := 1 //Top-right Quadrant
else
if (x > OriginX) and (y > OriginY) then Result := 2 //Bottom-right Quadrant
else
if (x < OriginX) and (y > OriginY) then Result := 3; //Bottom-left Quadrant
end;

It's a useful function especially for my wood cutter I'm making. It determines which quadrant I clicked in on the RuneScape main screen and then waits while the tree colour is in a certain place in that quadrant (while cutting).

Tested and it works. :)

mormonman

2009-12-03 19:31:57

I like it. Good work.

Edit: removed mine as it wouldn't set result to zero :S

TRiLeZ

2009-12-03 19:35:25

From: mormonman
I like it. Good work.


{*******************************************************************************
function WhichQuadrant(x, y, OriginX, OriginY: Extended): Integer;
By: TRiLeZ
Description: Results the Quadrant in which a point is in.
1 = TopRight 2 = BottomRight
3 = BottomLeft 4 = TopLeft
If the point is at the origin or between 2 quadrants, the result will be 0.
*******************************************************************************}
function WhichQuadrant(x, y, OriginX, OriginY: Extended): Integer;
begin
Result := 0;
if (x < OriginX) then
if (y < OriginY) then Result := 4 //Top-left Quadrant
else Result := 3; //Bottom-left Quadrant
else
if (x > OriginX) then
if (y < OriginY) then Result := 1 //Top-right Quadrant
else Result := 2; //Bottom-right Quadrant
end;


Thanks for shortening. I wonder why I can't shorten code that well… :p

mormonman

2009-12-03 19:37:29

It wasn't shortened… I had it shortened but it wouldn't ever result 0…

TRiLeZ

2009-12-03 19:51:42

From: mormonman
It wasn't shortened… I had it shortened but it wouldn't ever result 0…


You said it wasn't shortened but you had it shortening? It looks shorter but really isn't by much =/

We'll stick with my version of the function since it doesn't have any bugs.

Method

2009-12-03 20:40:50

Why do you use a quadrant system not consistent with the one used to represent 2D points in the cartesian coordinate system?

It also seems like your calculations aren't consistent with your descriptions of the quadrants, but maybe you updated one and forgot to change the other.

TRiLeZ

2009-12-05 19:23:46

Any other feedback?

Awkwardsaw

2009-12-05 20:07:11

function WhichQuadrant(x, y, OriginX, OriginY: Extended): Integer;
begin
Result := 0;
if (x > OriginX) and (y > OriginY) then Result := 1
else
if (x < OriginX) and (y > OriginY) then Result := 2
else
if (x < OriginX) and (y < OriginY) then Result := 3
else
if (x > OriginX) and (y < OriginY) then Result := 4;
end;

made it work like the cartassian coord plane :)

Method

2009-12-05 20:08:05

Yeah, you definitely calculated the quadrants incorrectly if your description is what you're going by. It should be like this:

{*******************************************************************************
function WhichQuadrant(x, y, OriginX, OriginY: Extended): Integer;
By: TRiLeZ
Description: Results the Quadrant in which a point is in. The first quadrant
is the top-right quadrant, which then increases in a clockwise order.
If the point is at the origin or between 2 quadrants, the result will be 0.
*******************************************************************************}
function WhichQuadrant(x, y, OriginX, OriginY: Extended): Integer;
begin
Result := 0;
if (x < OriginX) and (y > OriginY) then Result := 4 //Top-left Quadrant
else
if (x > OriginX) and (y > OriginY) then Result := 1 //Top-right Quadrant
else
if (x > OriginX) and (y < OriginY) then Result := 2 //Bottom-right Quadrant
else
if (x < OriginX) and (y < OriginY) then Result := 3; //Bottom-left Quadrant
end;

Also, why didn't you answer my question?

Awkwardsaw

2009-12-05 20:10:14

i like the Cartesian way better. :)

TRiLeZ

2009-12-05 20:21:18

From: Method
Yeah, you definitely calculated the quadrants incorrectly if your description is what you're going by. It should be like this:

{*******************************************************************************
function WhichQuadrant(x, y, OriginX, OriginY: Extended): Integer;
By: TRiLeZ
Description: Results the Quadrant in which a point is in. The first quadrant
is the top-right quadrant, which then increases in a clockwise order.
If the point is at the origin or between 2 quadrants, the result will be 0.
*******************************************************************************}
function WhichQuadrant(x, y, OriginX, OriginY: Extended): Integer;
begin
Result := 0;
if (x < OriginX) and (y > OriginY) then Result := 4 //Top-left Quadrant
else
if (x > OriginX) and (y > OriginY) then Result := 1 //Top-right Quadrant
else
if (x > OriginX) and (y < OriginY) then Result := 2 //Bottom-right Quadrant
else
if (x < OriginX) and (y < OriginY) then Result := 3; //Bottom-left Quadrant
end;

Also, why didn't you answer my question?


How is my description different than my function?
By my description it goes:
4 1
3 2
The quadrant number increases by 1 in a clockwise order.

Your rearranged function looks like:
3 2
4 1
The first quadrant isn't the top-right quadrant anymore and the quadrant numbers increases in a counter-clockwise order.

The reason why I didn't answer your question was because I didn't get what you were saying.

Method

2009-12-05 20:31:34

No, your code gives the following quadrants:

3 2
4 1

unless you're doing yet another unconventional thing with your x- and y-axes.

Conventionally, positive numbers on the x-axis are to the right of the y-axis, and positive numbers on the y-axis are above the x-axis.

TRiLeZ

2009-12-05 21:29:36

From: Method
No, your code gives the following quadrants:

3 2
4 1

unless you're doing yet another unconventional thing with your x- and y-axes.

Conventionally, positive numbers on the x-axis are to the right of the y-axis, and positive numbers on the y-axis are above the x-axis.


I see where you're coming from but you are wrong.
You are thinking it should be like this:

But, with RuneScape + SCAR, the more you go down on the Y axis, the more it increases.


Awkwardsaw

2009-12-05 21:34:48

that doesnt keep you from using the normal plane though. :p

TRiLeZ

2009-12-05 21:37:46

From: Awkwardsaw
that doesnt keep you from using the normal plane though. :p


I'll name the function to WhichRSQuadrant then. :p

marpis

2009-12-06 10:50:58

I don't see much use for this. You might find it useful but I doubt it would be very much used… Can't put every function someone finds useful to SRL you know. :-\