Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / Getting The Radius

Author
Message
t10dimensional
15
Years of Service
User Offline
Joined: 22nd Mar 2009
Location: Code Cave, USA
Posted: 16th Jun 2009 03:57
How do you get the radius of a circle.There's no command for it.

If at first you don't succeed-Pause-Go to last checkpoint
That1Smart Guy
15
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 16th Jun 2009 04:09
.....lets see, i found a way a while back on another thread, let me find it

ok heres the procedure:

pick any 3 points on the circle

imagine 3 lines connecting them all into a triangle

find the slope of those lines ((y1-y2)/(x1-x2))

find the midpoints of them

make line equations using a slope perpendicular to that of the triangle lines and make the line hit the midpoints of those lines

you now have 3 perpendicular bisectors of the triangle (segments that are perpendicular and hit at the midpoint of the sides)

set those line equations for the perpendicular bisectors equal to each other, then solve for x and y

that x and y is the circumcenter of the triangle AND is also the center of the circle

then just use distance formula to find the distance from that center to any point on the circle and bam, you have the radius

for more understanding of this process, see this thread:

http://forum.thegamecreators.com/?m=forum_view&t=150827&b=10

There are only 10 kinds of people in the world, those who understand binary and those who dont
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 16th Jun 2009 04:11 Edited at: 16th Jun 2009 04:13
I think DB draws circles with the "size" as the diameter, so half of that would be the radius.

[edit]
@smartguy
how did you manage to write all that before mine?

There is an eight letter word. You can insert a letter into it or remove a letter from it without changing its meaning. Answer
That1Smart Guy
15
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 16th Jun 2009 04:12
i think you missed my huge post above obese and no DBC draw circles with the radius so im not sure how you wouldnt know the radius but watevr

There are only 10 kinds of people in the world, those who understand binary and those who dont
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 16th Jun 2009 04:14
yes I think this is a sign I should go to bed

There is an eight letter word. You can insert a letter into it or remove a letter from it without changing its meaning. Answer
That1Smart Guy
15
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 16th Jun 2009 04:19
lol, also what are you needing this for razer?

There are only 10 kinds of people in the world, those who understand binary and those who dont
t10dimensional
15
Years of Service
User Offline
Joined: 22nd Mar 2009
Location: Code Cave, USA
Posted: 16th Jun 2009 04:47
I need to check if the mousex() and mousey() is inside a certain size circle.

If at first you don't succeed-Pause-Go to last checkpoint
That1Smart Guy
15
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 16th Jun 2009 04:56
just use the functions in my DBC challenge entry, there are two, circlemouseover and distance#, you will need both

circlemouseover does exactly that and uses distance#

There are only 10 kinds of people in the world, those who understand binary and those who dont
t10dimensional
15
Years of Service
User Offline
Joined: 22nd Mar 2009
Location: Code Cave, USA
Posted: 16th Jun 2009 05:08
Thanks, I'll see if I can understand how it works.

If at first you don't succeed-Pause-Go to last checkpoint
t10dimensional
15
Years of Service
User Offline
Joined: 22nd Mar 2009
Location: Code Cave, USA
Posted: 16th Jun 2009 05:15
Quote: "function circlemouseover(x,y,rad)
mx=mousex() : my=mousey()
dist#=distance#(mx,my,x,y)
if dist#<=rad then exitfunction 1
endfunction 0

function distance#(x1,y1,x2,y2)
dist#=sqrt(((x2-x1)*(x2-x1))+((y2-y1)*(y2-y1)))
dist#=abs(dist#)
endfunction dist#"

Alright,
I see what you did up to
if dist#<=rad then exitfunction 1
I don't see where you set a value to "rad".

If at first you don't succeed-Pause-Go to last checkpoint
That1Smart Guy
15
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 16th Jun 2009 05:16
if i recall correctly you just input the center coordinate of the circloe and the radius, then it calculates the distance from the center of the circle to mx,my and if its less than the radius then it spits out a 1 otherwise a 0

There are only 10 kinds of people in the world, those who understand binary and those who dont
t10dimensional
15
Years of Service
User Offline
Joined: 22nd Mar 2009
Location: Code Cave, USA
Posted: 16th Jun 2009 05:19
You seem to always answer my math Q's,thanks.

If at first you don't succeed-Pause-Go to last checkpoint
That1Smart Guy
15
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 16th Jun 2009 05:24
np

There are only 10 kinds of people in the world, those who understand binary and those who dont
TheComet
16
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 16th Jun 2009 23:10
Ah, Pythagoras!

Yes, that is how you should do it. But to speed things up a bit, because the sqrt() command is very slow, try leaving the sqrt() away:



And then use:



Also note that rad^2 is MUCH slower than rad*rad.

TheComet


Make the path of your enemies easier with Waypoint Pro!
That1Smart Guy
15
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 17th Jun 2009 00:39
interesting, although unless you're doing it ALOT the speed really wont matter so long as it works and makes sense to you

There are only 10 kinds of people in the world, those who understand binary and those who dont
TheComet
16
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 17th Jun 2009 08:38
Quite true, but it is a good habbit to write the fastest code from the beginning, than changing it later.

TheComet


Make the path of your enemies easier with Waypoint Pro!
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 17th Jun 2009 16:44
Quote: "interesting, although unless you're doing it ALOT the speed really wont matter so long as it works and makes sense to you
"

You should always assume you'll be doing it a lot.

There is an eight letter word. You can insert a letter into it or remove a letter from it without changing its meaning. Answer

Login to post a reply

Server time is: 2024-05-20 09:48:09
Your offset time is: 2024-05-20 09:48:09