CGTalk arc between two points?
 Thread Closed share thread « Previous Thread | Next Thread »
 Thread Tools Search this Thread Display Modes
 06-17-2013, 10:58 PM #1 JokerMartini Expert   portfolio John Martini CG Supervisor, 3D, Maxscript, VFX Ingenuity Engine Los Angeles, USA   Join Date: Mar 2009 Posts: 1,299 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. share quote
 06-18-2013, 04:02 PM #2 JokerMartini Expert   portfolio John Martini CG Supervisor, 3D, Maxscript, VFX Ingenuity Engine Los Angeles, USA   Join Date: Mar 2009 Posts: 1,299 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. share quote
 06-18-2013, 04:33 PM #3 JokerMartini Expert   portfolio John Martini CG Supervisor, 3D, Maxscript, VFX Ingenuity Engine Los Angeles, USA   Join Date: Mar 2009 Posts: 1,299 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 share quote
06-18-2013, 06:35 PM   #4
gazybara
Architect

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]

 06-18-2013, 07:15 PM #5 Swordslayer isKindOf Artist   portfolio Vojtech Cada 3D generalist Czech Republic   Join Date: Jun 2006 Posts: 358 Have a look at createCircumcircle function in CAD Circle (needs barycentricToWorld to work, you can ignore the rest). __________________ Blog :: LinkedIn profile share quote
 06-18-2013, 07:37 PM #6 JokerMartini Expert   portfolio John Martini CG Supervisor, 3D, Maxscript, VFX Ingenuity Engine Los Angeles, USA   Join Date: Mar 2009 Posts: 1,299 Alright ill check that out. Thank you __________________ ____________ ___ __ _ John A. Martini JokerMartini@hotmail.com www.JokerMartini.com share quote
06-19-2013, 06:05 AM   #7
denisT
MAX Doctor

portfolio
Denis Trofimov
CA, USA

Join Date: Jul 2009
Posts: 9,321
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?

 06-19-2013, 07:24 AM #8 Swordslayer isKindOf Artist   portfolio Vojtech Cada 3D generalist Czech Republic   Join Date: Jun 2006 Posts: 358 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 share quote
06-19-2013, 10:29 AM   #9
denisT
MAX Doctor

portfolio
Denis Trofimov
CA, USA

Join Date: Jul 2009
Posts: 9,321
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.

 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 share quote
 06-19-2013, 01:25 PM #11 JokerMartini Expert   portfolio John Martini CG Supervisor, 3D, Maxscript, VFX Ingenuity Engine Los Angeles, USA   Join Date: Mar 2009 Posts: 1,299 Thanks Gravey I'll check this thread out as welll __________________ ____________ ___ __ _ John A. Martini JokerMartini@hotmail.com www.JokerMartini.com share quote
 06-19-2013, 07:52 PM #12 Swordslayer isKindOf Artist   portfolio Vojtech Cada 3D generalist Czech Republic   Join Date: Jun 2006 Posts: 358 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 share quote
 06-19-2013, 09:04 PM #13 denisT MAX Doctor   portfolio Denis Trofimov CA, USA   Join Date: Jul 2009 Posts: 9,321 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... share quote
06-19-2013, 09:43 PM   #14
gazybara
Architect

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]

 06-19-2013, 09:43 PM #15 CGTalk Moderation Lord of the posts   Join Date: Sep 2003 Posts: 1,066,481 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. share quote
 Thread Closed share thread

 Thread Tools Search this Thread Search this Thread: Advanced Search Display Modes Linear Mode

 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 vBulletinCopyright ©2000 - 2006, Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
 Please select one User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home -------------------- Gallery     Latest Entries     Featured Videos     Featured 3D     Featured 2D     CG Awards     Expose12 Call For Entries Main     News         Press Releases and Media     General Discussion     Off Topic     Recruitment     Education Software     Autodesk Maya         Maya Dynamics         Maya Rendering         Maya Character Setup         Maya Programming     Austodesk Miscellaneous         Autodesk MotionBuilder         Autodesk Mudbox         Autodesk Softimage             XSI: Programming             ICE: Interactive Creative Environment     Autodesk 3ds max         3dsMax SDK and MaxScript         3dsMax Tutorials & Tips         3dsMax Resources         Plugins & Add-ons         Particle Flow     Maxon Cinema 4D         Cinema 4D Resources     The Foundry Modo         The Foundry Time Travel Challenge     Pixologic ZBrush     Photoshop / Painter     Side Effects Houdini     Blender     Lightwave 3D         LW Resources         LW Tutorials     E-on Software Vue     Compositing Software         The Foundry Nuke         Adobe After Effects         Autodesk Effects and Compositing         Eyeon Software Digital Fusion Challenges     Thrust Sponsered Challenge     Modeling Challenge         Member Model Collection     Digital Matte Painting Challenge     Rigging Challenge     Sketch Challenge         Member SKETCH Collection     FXWARS Challenge         Member FXGallery     Animation Challenge         Past Sessions Archive     Lighting Challenges WIP     Professional Feedback     WIP/Critique: 3D     WIP/Critique: 2D         Speedpaints & Sketchbooks     WIP/Critique: Animation     Collaborative Projects Techniques     Art Techniques and Theories     Digital Matte Painting         Digital Matte Painting Mini-Challenge     Modeling     Texturing and Surfacing     Character Rigging     Animation     Lighting and Shaders     Compositing and Editing     Anatomy and Figurative Art         SPOTLIGHT: Best of the Artistic Anatomy and Figurative Art Forum         Tutorials and Workshops         Personal Anatomy & Sketchbook Threads         References, Resources, and Supplies Technical     Virtual Reality     Game Engine     Graphics Programming     Technical and Hardware Support     CGSociety Support Forum         FAQ         Suggestions
Miscellaneous

All times are GMT. The time now is 09:58 PM.

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