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 / Finding middle of circle around a triangle

Author
Message
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 17th May 2009 22:28
Hello!

I have 3 points in 2 dimensions. I know the positions of them and I defined them as x1,y1 - x2,y2 - x3,y3. These points make a triangle.



How can I find the center of the circle (red cross) by only knowing the 3 positions of the triangles corners?

Thanks, TheComet

Peachy, and the Chaos of the Gems

Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 17th May 2009 22:46
I don't think you can, not based on a single triangle like that. If one of the chords crossed through the center, or if you had a right triangle, then maybe. If there was a way to get the angle of an arc between two of the points then maybe we could determine the circumference and go from there. But right now I'm not seeing any way. Maybe one of those crazy math genius on here will know.

[url="http://dbcc.zimnox.com"][/url]
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 17th May 2009 23:03 Edited at: 17th May 2009 23:03


There is no triangle where a circle can not be drawn through all 3 points. You have to draw a line vertical to each side of the triangle through the center of the side, and where all three lines cross is where the circle middle point is. I just don't know how to calculate that with maths...

TheComet

Peachy, and the Chaos of the Gems

BN2 Productions
21
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 17th May 2009 23:35
You could find the distance from the three points algebraically and set them equal to each other.

D^2=(X1-Cx)^2+(Y1-Cy)^2
D^2=(X2-Cx)^2+(Y2-Cy)^2
D^2=(X3-Cx)^2+(Y3-Cy)^2

These basically make a circle of radius D around each and setting them equal will find where they intersect.

See?



Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 17th May 2009 23:45
I don't quite get you... How do I know the radius of those 3 circles? and what is Cx and Cy?

TheComet

Peachy, and the Chaos of the Gems

t10dimensional
16
Years of Service
User Offline
Joined: 22nd Mar 2009
Location: Code Cave, USA
Posted: 18th May 2009 00:20
They should make a board just for math quetions.(just a random thought)

If at first you don't succeed-Pause-Go to last checkpoint
pictionaryjr
16
Years of Service
User Offline
Joined: 12th Mar 2009
Location:
Posted: 18th May 2009 00:30 Edited at: 18th May 2009 00:32
If you could find out the length of the sides you could use SohCahToa

Sin=Opposite/Hypotenuse
Cos=Adjacent/Hypotenuse
Tan=Opposite/Adjacent


Then with the angles, determine the arc of the circle.

Not really sure about this whole concept, but I remember doing something in math like this not too long ago. I think the triangle has to be a right triangle though.

I'll search around and see if I can remember.
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 18th May 2009 00:38 Edited at: 18th May 2009 00:41
a right triangle would sure make it easier since a right triangle would have the hypotenuse being a diameter, so all ud have to do is take the hypotenuse length and divide it by 2 to get the radius and the center would be the midpoint of the hypotenuse

but im sure theres a way

[edit]
i think this would work, if u know the coordinates of the 3 points then ud have everything u need to find the center if this is corect

http://local.wasp.uwa.edu.au/~pbourke/geometry/circlefrom3/

There are only 10 kinds of people in the world, those who understand binary and those who dont
BN2 Productions
21
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 18th May 2009 00:42 Edited at: 18th May 2009 01:12
Cx and Cy are the Center Points X and Y, repectively.

You don't know the radius, but since all three equations yield the same result (D^2, that is, the radius squared), You can eliminate it like so:

D^2=(X1-Cx)^2+(Y1-Cy)^2
D^2=(X2-Cx)^2+(Y2-Cy)^2
D^2=(X3-Cx)^2+(Y3-Cy)^2

(X1-Cx)^2+(Y1-Cy)^2=(X2-Cx)^2+(Y2-Cy)^2=(X3-Cx)^2+(Y3-Cy)^2

It will require some algebra, I will see what I can do.

[EDIT]
I know I JUST posted, but I forgot to post, so I posted, then realized I had finished

Here you go:
Where:
(X1,Y1)=Coords of point 1
(X2,Y2)=Coords of point 2
(X3,Y3)=coords of point 3

I will do this in 2 parts for ease of understanding (lots of parenthesis)

Cytop=(x1-x2)(y3^2-y2^2-x2^2-x3^2)-(x2-x3)(y2^2-y1^2-x1^2-x2^2)
Cybottom=(x2-x3)(-2)(y2-y1)+(x1-x2)(2)(y3-y2)
Cy=Cytop/Cybottom

That should actually be usable code too

Once you find CY you can find Cx by:

Cxtop= -(y2^2-y1^2)-(2)(Cy)(y2-y1)-(x1^2-x2^2)
Cxbottom= 2(x1-x2)
Cx=Cxtop/Cxbottom

DON'T FORGET TO ACCOUNT FOR DIVIDE BY 0 ERRORS!!!

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 18th May 2009 00:44 Edited at: 18th May 2009 01:23
ya that would work, but i think mine is simpler, ill post a function to calculate it here in a few mins

[edit]
ok, i cant find a way to make this into a function, but heres how you would compute it

say A,B,C are the 3 points

find the slope of segments AB and BC using (y1-y2)/(x1-x2)

find the midpoints of those same lines using x=(x1+x2)/2 and y=(y1+y2)/2

find the slope perpendicular to those lines by using -1/m, where m is the slope of the line

fill in y-y1=m(x-x1) where y and x are constants, m is the perpendicular slope and (x1,y1) is the coordinate for the midpoint of the 1st line

convert this into y=m*x + b, where again y and x are constants, m is the perp. slope and b is the y intercept of our new perpendicular line (the y coordinate where the line crosses the y axis)

chop of the y's of our 2 perp. line formulas and set the rest equal to each other (you should now only have 2 unknown, x), so it will be m1*x + b1 = m2*x + b2 where again x is constant, m1 and m2 are slopes of the perp. lines and b1 & b2 are the y intercepts

solve for x, which is the x of our circle center

fill that back into one of the perp. line equations (y=m*x = b), then solve for y which is the y coordinate of the center

wow that was a rant, hope it helped though

There are only 10 kinds of people in the world, those who understand binary and those who dont
AndrewT
18
Years of Service
User Offline
Joined: 11th Feb 2007
Location: MI, USA
Posted: 18th May 2009 03:52 Edited at: 18th May 2009 04:37
Wow, you guys are making this WAY too complicated, with all your fancy algebraic equations. That1Smart Guy is living up to his name--he's got the idea. You simply find the perpendicular bisectors of each side of the triangle and find the intersection point. That's the center. The radius is the distance to any of the vertices of the triangle. I'll post some code in a sec.

EDIT:

Crap--I forgot, I have DBP, not DBC. Anyways here's what I came up with:



Thanks to Mr Kohlenstoff (sp?) for the line intersection. You can move one point of the triangle with the mouse. If anyone here is kind enough to convert this to DBC that'd be great.

However hopefully it should get across the general idea regardless of whether or not you can run it. Basically, first you find the slope and midpoint of each edge. Then you find the negative reciprocal of each edge:

NegRecip = -1 / Slope

That, combined with the midpoint of that edge will give you the edge's perpendicular bisector. Then you find the intersection of two of these lines using a function like the one I used, and the intersection point is the circumcenter. You can find the radius by finding the distance between any point and the circumcenter, which gives you your circumcircle.

If you have any questions feel free to ask, especially since you probably can't run the code.

Little screen shot because most of you don't have DBP:



EDIT2:

I'm working on a DBC-compatible function right now, so no one needs to convert this. Hopefully I can post it by tomorrow morning.

i like orange
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 18th May 2009 04:37
so thats why my geometry teacher taught us perpendicular bisectors and circumcenters, cool!

i totally 4got thats what those were!!! lol

There are only 10 kinds of people in the world, those who understand binary and those who dont
AndrewT
18
Years of Service
User Offline
Joined: 11th Feb 2007
Location: MI, USA
Posted: 18th May 2009 05:16
Ok, I've reduced my earlier snippet to the very bare minimum:



I changed all UDTs into several arrays, one for each field, and I changed all globals into arrays with one index, so (hopefully) it should compile with DBC, and if it can't the changes that need to be made are minimal. Anyways it's very easy to use. Simply call CircumInit() at the beginning of your program, then call Circumcenter(), passing each point of your triangle as the parameters. Then to get the center call CCX()/CCY() and to get the radius call CCRadius().

Hope that helps.

i like orange
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 18th May 2009 05:22
cool, show off

lol jk

There are only 10 kinds of people in the world, those who understand binary and those who dont
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 18th May 2009 10:38
That was awesome, AndrewT! Thanks to everyone that helped out on this!

Here is the code for DBC:



TheComet

Peachy, and the Chaos of the Gems

AndrewT
18
Years of Service
User Offline
Joined: 11th Feb 2007
Location: MI, USA
Posted: 18th May 2009 13:22
No problem, glad I could help.

i like orange

Login to post a reply

Server time is: 2025-05-17 07:16:50
Your offset time is: 2025-05-17 07:16:50