CGTalk > Software > Autodesk 3ds max > 3dsMax SDK and MaxScript
Login register
Thread Closed share thread « Previous Thread | Next Thread »  
 
Thread Tools Search this Thread Display Modes
Old 06-17-2013, 10:58 PM   #1
JokerMartini
Expert
 
JokerMartini's Avatar
portfolio
John Martini
CG Supervisor, 3D, Maxscript, VFX
Ingenuity Engine
Los Angeles, USA
 
Join Date: Mar 2009
Posts: 1,307
Send a message via AIM to JokerMartini
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-18-2013 at 04:02 PM.
 
Old 06-18-2013, 04:02 PM   #2
JokerMartini
Expert
 
JokerMartini's Avatar
portfolio
John Martini
CG Supervisor, 3D, Maxscript, VFX
Ingenuity Engine
Los Angeles, USA
 
Join Date: Mar 2009
Posts: 1,307
Send a message via AIM to JokerMartini
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-18-2013 at 04:32 PM.
 
Old 06-18-2013, 04:33 PM   #3
JokerMartini
Expert
 
JokerMartini's Avatar
portfolio
John Martini
CG Supervisor, 3D, Maxscript, VFX
Ingenuity Engine
Los Angeles, USA
 
Join Date: Mar 2009
Posts: 1,307
Send a message via AIM to JokerMartini
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-18-2013, 06:35 PM   #4
gazybara
Architect
 
gazybara's Avatar
portfolio
Branko Živković
Freelancer
Niš, Serbia
 
Join Date: Apr 2011
Posts: 1,103
Quote:
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:
Code:
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-18-2013, 07:15 PM   #5
Swordslayer
isKindOf Artist
 
Swordslayer's Avatar
portfolio
Vojtech Cada
3D generalist
Czech Republic
 
Join Date: Jun 2006
Posts: 371
Send a message via ICQ to Swordslayer
Have a look at createCircumcircle function in CAD Circle (needs barycentricToWorld to work, you can ignore the rest).
__________________
Blog :: LinkedIn profile
 
Old 06-18-2013, 07:37 PM   #6
JokerMartini
Expert
 
JokerMartini's Avatar
portfolio
John Martini
CG Supervisor, 3D, Maxscript, VFX
Ingenuity Engine
Los Angeles, USA
 
Join Date: Mar 2009
Posts: 1,307
Send a message via AIM to JokerMartini
Alright ill check that out.
Thank you
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com
 
Old 06-19-2013, 06:05 AM   #7
denisT
MAX Doctor
 
denisT's Avatar
portfolio
Denis Trofimov
CA, USA
 
Join Date: Jul 2009
Posts: 9,511
Send a message via ICQ to denisT
Quote:
Originally Posted by Swordslayer
Have a look at createCircumcircle function in CAD Circle (needs barycentricToWorld to work, you can ignore the rest).

i like:
Code:
dot a a

is it your trick?
 
Old 06-19-2013, 07:24 AM   #8
Swordslayer
isKindOf Artist
 
Swordslayer's Avatar
portfolio
Vojtech Cada
3D generalist
Czech Republic
 
Join Date: Jun 2006
Posts: 371
Send a message via ICQ to Swordslayer
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.
__________________
Blog :: LinkedIn profile
 
Old 06-19-2013, 10:29 AM   #9
denisT
MAX Doctor
 
denisT's Avatar
portfolio
Denis Trofimov
CA, USA
 
Join Date: Jul 2009
Posts: 9,511
Send a message via ICQ to denisT
Quote:
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-19-2013 at 10:44 AM.
 
Old 06-19-2013, 11:46 AM   #10
Gravey
3D Dude
Joel Hewitt
Sydney, Australia
 
Join Date: Dec 2005
Posts: 880
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-19-2013, 01:25 PM   #11
JokerMartini
Expert
 
JokerMartini's Avatar
portfolio
John Martini
CG Supervisor, 3D, Maxscript, VFX
Ingenuity Engine
Los Angeles, USA
 
Join Date: Mar 2009
Posts: 1,307
Send a message via AIM to JokerMartini
Thanks Gravey I'll check this thread out as welll
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com
 
Old 06-19-2013, 07:52 PM   #12
Swordslayer
isKindOf Artist
 
Swordslayer's Avatar
portfolio
Vojtech Cada
3D generalist
Czech Republic
 
Join Date: Jun 2006
Posts: 371
Send a message via ICQ to Swordslayer
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.

Code:
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):

Code:
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,

Code:
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:

Code:
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
__________________
Blog :: LinkedIn profile
 
Old 06-19-2013, 09:04 PM   #13
denisT
MAX Doctor
 
denisT's Avatar
portfolio
Denis Trofimov
CA, USA
 
Join Date: Jul 2009
Posts: 9,511
Send a message via ICQ to denisT
what's wrong with this one:
Code:
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-19-2013, 09:43 PM   #14
gazybara
Architect
 
gazybara's Avatar
portfolio
Branko Živković
Freelancer
Niš, Serbia
 
Join Date: Apr 2011
Posts: 1,103
Quote:
Originally Posted by denisT
what's wrong with this one:
Code:
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-19-2013, 09:43 PM   #15
CGTalk Moderation
Lord of the posts
CGTalk Forum Leader
 
Join Date: Sep 2003
Posts: 1,066,480
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 05:11 PM.


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