arc between two points?

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 06 June 2013   #1
circle from three points

Say I have three points [0,0] [30,20] [25,-5]

How can I find the center and radius of the circle?

I'm having a tough time wrapping my head around the math for it.
http://www.had2know.com/academics/c...ree-points.html
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com

Last edited by JokerMartini : 06 June 2013 at 04:02 PM.
 
Old 06 June 2013   #2
In the end I'm just trying to write a function that I can pass three points and it return me the radius and center of the circle. Kinda like

fn calcCircle A:[0,0] B:[0,0] C:[0,0] =
(
return #(radius,center)
)

http://paulbourke.net/geometry/circlesphere/
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com

Last edited by JokerMartini : 06 June 2013 at 04:32 PM.
 
Old 06 June 2013   #3
In the end I'm just trying to write a function that I can pass three points and it return me the radius and center of the circle. Kinda like

fn calcCircle A:[0,0] B:[0,0] C:[0,0] =
(
return #(radius,center)
)

http://paulbourke.net/geometry/circlesphere/
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com
 
Old 06 June 2013   #4
Originally Posted by JokerMartini: Say I have three points [0,0] [30,20] [25,-5]

How can I find the center and radius of the circle?

I'm having a tough time wrapping my head around the math for it.
http://www.had2know.com/academics/c...ree-points.html

I find correct radius of in circle but incenter position is not good.
Example:

delete objects
spl = splineshape()
addNewSpline spl
addKnot spl 1 #corner #line [-50,-30,0]
addKnot spl 1 #corner #line [0,100,0]
addKnot spl 1 #corner #line [60,40,0]
close spl 1
spl.pivot = spl.center
updateshape spl
p1 = getknotpoint spl 1 1
p2 = getknotpoint spl 1 2
p3 = getknotpoint spl 1 3
A = distance p1 p2
B = distance p2 p3
C = distance p1 p3
S = (A+B+C)/2
P = sqrt(S*(S-A)*(S-B)*(S-C))
circle_radius = P/S
circle_center = ((p1+p2+p3)/(A+B+C))*spl.transform
circle pos:circle_center radius:circle_radius
__________________
Looking in the right side. [bgaTools]
 
Old 06 June 2013   #5
Have a look at createCircumcircle function in CAD Circle (needs barycentricToWorld to work, you can ignore the rest).
__________________
Scripts :: linkedin
 
Old 06 June 2013   #6
Alright ill check that out.
Thank you
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com
 
Old 06 June 2013   #7
Originally Posted by Swordslayer: Have a look at createCircumcircle function in CAD Circle (needs barycentricToWorld to work, you can ignore the rest).

i like:

dot a a

is it your trick?
 
Old 06 June 2013   #8
It's my substitution to the wiki/mathworld formulas here ((lenght vec)^2 to be more specific) but originally I got it from some presentation of usefulness of dot product in 3d graphics.
__________________
Scripts :: linkedin
 
Old 06 June 2013   #9
Originally Posted by Swordslayer: (lenght vec)^2 to be more specific

that's why i liked it... because the length is sqrt(x*x + y*y + z*z) or sqrt(dot vec vec)... cool

Last edited by denisT : 06 June 2013 at 10:44 AM.
 
Old 06 June 2013   #10
circumcentre of 3 points posted in the geometric calculations thread here

radius is just the distance from cc to any of the 3 points
 
Old 06 June 2013   #11
Thanks Gravey I'll check this thread out as welll
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com
 
Old 06 June 2013   #12
Gravey: Gosh, I miss the days of college maths... wait, maybe not all that much Anyway, the functions are just a few substitutions away. For a start, let's say we switch the distance function for a lenght of vector.

fn circumcenter p1 p2 p3 = 
  (
  	local BC = length (p3 - p2)
  	local CA = length (p3 - p1)
  	local AB = length (p2 - p1)
  	
  	local u = BC^2*(CA^2+AB^2-BC^2)
  	local v = CA^2*(AB^2+BC^2-CA^2)
  	local w = AB^2*(BC^2+CA^2-AB^2)
  
  	barycentricToWorld p1 p2 p3 u v w
  )


This is just to make the transtion easier to follow, as we now use each of these vectors as a variable and the dot product of the vector with itself substitutes the squared distance (getting rid of squaring the square root):

fn circumcenter p1 p2 p3 = 
  (
  	local a = p3 - p2
  	local b = p3 - p1
  	local c = p2 - p1
  	
  	local u = dot a a * (dot b b + dot c c - dot a a)
  	local v = dot b b * (dot c c + dot a a - dot b b)
  	local w = dot c c * (dot a a + dot b b - dot c c)
  
  	barycentricToWorld p1 p2 p3 u v w
  )


Now, all the negative dot product terms can also be subsituted,

	dot a a == dot (b - c) (b - c)
  	dot a a == dot b b - 2 * dot b c + dot c c
  	
  	dot b b == dot (c - -a) (c - -a)
  	dot b b == dot c c - 2 * dot c -a + dot a a --> dot -a -a == dot a a
  
  	dot c c == dot (a - b) (a - b)
  	dot c c == dot a a - 2 * dot a b + dot b b


So the three terms are in the end:

	dot a a * (dot b b + dot c c - dot b b + 2 * dot b c - dot c c)
  	--> 2 * dot a a * dot b c
  
  	dot b b * (dot c c + dot a a - dot c c + 2 * dot c -a - dot a a)
  	--> 2 * dot b b * dot c -a
  
  	dot c c *  (dot a a + dot b b - dot a a + 2 * dot a b - dot b b)
  	--> 2 * dot c c * dot a b


No square root anymore, just basic multiplication and stuff - of course here it's no big deal
__________________
Scripts :: linkedin
 
Old 06 June 2013   #13
what's wrong with this one:

fn circumcenter p1 p2 p3 =
(
	fn barycentricToWorld p1 p2 p3 u v w = (u*p1 + v*p2 + w*p3) / (u + v + w)

	local a = p3 - p2
	local b = p1 - p3
	local c = p2 - p1

	local u = (dot a a) * (dot c b)
	local v = (dot b b) * (dot c a)
	local w = (dot c c) * (dot b a)

	barycentricToWorld p1 p2 p3 u v w
)

fastest, cleanest...
 
Old 06 June 2013   #14
Originally Posted by denisT: what's wrong with this one:

 fn circumcenter p1 p2 p3 =
 (
 	fn barycentricToWorld p1 p2 p3 u v w = (u*p1 + v*p2 + w*p3) / (u + v + w)
 
 	local a = p3 - p2
 	local b = p1 - p3
 	local c = p2 - p1
 
 	local u = (dot a a) * (dot c b)
 	local v = (dot b b) * (dot c a)
 	local w = (dot c c) * (dot b a)
 
 	barycentricToWorld p1 p2 p3 u v w
 )
 

fastest, cleanest...

Nothing it's just perfect. Anyway thanks Swordslayer for very informative math lesson.
__________________
Looking in the right side. [bgaTools]
 
Old 06 June 2013   #15
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright ©2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 11:25 PM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.