+ Reply to Thread
Page 2 of 3 FirstFirst 1 2 3 LastLast
Results 11 to 20 of 21

Thread: [Extreme Math] Calculating a point equidistant from 3 others

  1. #11
    Wire Illusionist


    Jimlad will become famous soon enough Jimlad's Avatar
    Join Date
    Dec 2008
    Posts
    861

    Default Re: [Extreme Math] Calculating a point equidistant from 3 others

    Yeah like HP said, if you just need the middle of a group of objects just average the points. You should have said that at the start! Being "in the middle of" is not the same as "equidistant from", in fact the two are very different except in special cases. You should avoid using specific terminology when you aren't being specific about the meaning.

  2. #12
    Master of Mars


    Magos Mechanicus will become famous soon enough Magos Mechanicus will become famous soon enough Magos Mechanicus's Avatar
    Join Date
    May 2008
    Posts
    834

    Default Re: [Extreme Math] Calculating a point equidistant from 3 others

    Aww, it's not needed after all.

    Anyways, I thought that trilateration stuff sounded like an interesting problem, so I made an E2 to do the necessary coordinate transformations. Then I discover the circumcenter, which let me find the equidistant point much easier, and having the coordinate transformations done already it was quite easy to find. Here's the result. It'll find the circumcenter equidistant to any 3 points that have one (i.e. are not on a line).

    e2 Code:
    1. @name Circumcenter
    2. @inputs A:vector B:vector C:vector
    3. @outputs Circumcenter:vector
    4. #Coordinate transformations
    5. #First things first:
    6. #Finding an orthonormal basis.
    7. I = (B-A):normalized()
    8. J = (C-A):normalized()
    9. J = (J-J:dot(I)*I):normalized()
    10. if(!J){exit()} #If A,B,C are on a line, then exit before we get divide by 0 and such
    11. K = J:cross(I)
    12. RefFrame=transpose(matrix(I,J,K))
    13. #Finding the position vectors of the 3 points
    14. #in our new reference frame.
    15. A2 = vec()
    16. B2 = RefFrame*(B-A)
    17. C2 = RefFrame*(C-A)
    18.  
    19. #Finding the circumcenter in local coords
    20. BisectX = B2:x()/2
    21. BisectC = C2/2
    22. DirC = vec(0,0,1):cross(C2):normalized()
    23. DistC = (BisectX-BisectC:x())/DirC:x()
    24. Circumcenter2 = BisectC + DistC*DirC
    25.  
    26. #Transforming results to world coords
    27. Circumcenter = A + RefFrame^-1*Circumcenter2
    Last edited by Magos Mechanicus; 05-10-2009 at 01:29 PM.
    I can wire anything directly into anything! I'm the Professor!
    -Professor Hubert Farnsworth

  3. #13
    I think I think too much

    -HP- has a spectacular aura about -HP- has a spectacular aura about -HP- has a spectacular aura about -HP-'s Avatar
    Join Date
    Feb 2009
    Location
    Behind you with a very sharp knife.
    Posts
    2,239

    Default Re: [Extreme Math] Calculating a point equidistant from 3 others

    Quote Originally Posted by Magos Mechanicus View Post
    Aww, it's not needed after all.

    Anyways, I thought that trilateration stuff sounded like an interesting problem, so I made an E2 to do the necessary coordinate transformations. Then I discover the circumcenter, which let me find the equidistant point much easier, and having the coordinate transformations done already it was quite easy to find. Anyways, here's the result. It'll find the circumcenter equidistant to any 3 points that have one (i.e. are not on a line).

    e2 Code:
    1. @name Circumcenter
    2. @inputs A:vector B:vector C:vector
    3. @outputs Circumcenter:vector
    4. #Coordinate transformations
    5. #First things first:
    6. #Finding an orthonormal basis.
    7. I = (B-A):normalized()
    8. J = (C-A):normalized()
    9. J = (J-J:dot(I)*I):normalized()
    10. K = J:cross(I)
    11. RefFrame=transpose(matrix(I,J,K))
    12. #Finding the position vectors of the 3 points
    13. #in our new reference frame.
    14. A2 = vec()
    15. B2 = RefFrame*(B-A)
    16. C2 = RefFrame*(C-A)
    17.  
    18. #Finding the circumcenter in local coords
    19. BisectX = B2:x()/2
    20. BisectC = C2/2
    21. DirC = vec(0,0,1):cross(C2):normalized()
    22. DistC = (BisectX-BisectC:x())/DirC:x()
    23. Circumcenter2 = BisectC + DistC*DirC
    24.  
    25. #Transforming results to world coords
    26. Circumcenter = A + RefFrame^-1*Circumcenter2
    Wow. I've no idea what the hell you do in that expression, it's faaaaar beyong me. Awesome, will keep that in mind and see if I need it sometime

    if you sign up using my link you get extra space!

    also this

  4. #14
    Wire Illusionist


    Jimlad will become famous soon enough Jimlad's Avatar
    Join Date
    Dec 2008
    Posts
    861

    Default Re: [Extreme Math] Calculating a point equidistant from 3 others

    haha, good stuff. Yeah I guess the circumcentre is probably the most direct way of finding one of the equidistant points. I haven't thought about it much, but I guess there are two others, opposite to each other normal to the plane of the triangle? Cool use of the matrix functions! I like how, rather than messing about with general formulae, you simplified it and just aligned the axes with the points.

  5. #15
    Master of Mars


    Magos Mechanicus will become famous soon enough Magos Mechanicus will become famous soon enough Magos Mechanicus's Avatar
    Join Date
    May 2008
    Posts
    834

    Default Re: [Extreme Math] Calculating a point equidistant from 3 others

    Thanks. I think that's right, though they may take some more pondering to find. They wouldn't be at the same distance as the circumcenter, would they? Also, using matrix*vector to transform coordinates was a lifesaver in the below stuff particularly because you can scale matrices by a scalar, so thanks for adding them.

    So today I finally got E2 holograms working and my first project to try and learn that was to illustrate the method in the above expression. The holo portion came out as about half of the gate afterwards, but it looks so cool I guess that's ok.

    I find it works best to take 3 GPSes and hook their vector outputs up to A,B and C, then jiggle them about relative to one another and watch the reaction. Use Hologramscale to scale the holograms - at 1 you should be able to line the GPSes up with the respective points (though it's tricky), at 0.5 the figure is at half size, at 2 it's at double size and so on. If Hologramscale is 0 the holograms are not used. By default it shows the triangle formed by the three input points - the red side goes from A (directly above the expression) to B, and the last point is C. The little cube marks the circumcenter. You can turn on Guidelines to see the two lines I use to find the circumcenter; it's found where they intersect. Each starts on the halfway mark of the respective triangle side and is normal to it. The last option is to turn on the circumcircle, just to show that it is indeed equidistant to the 3 points.

    e2 Code:
    1. @name Circumcenter
    2. @inputs A:vector B:vector C:vector
    3. @inputs Hologramscale Guidelines Circumcircle
    4. @outputs Circumcenter:vector C2:vector
    5. #Coordinate transformations
    6. #First things first:
    7. #Finding an orthonormal basis.
    8. I = (B-A):normalized()
    9. J = (C-A):normalized()
    10. J = (J-J:dot(I)*I):normalized()
    11. if(!J){exit()} #If A,B,C are on a line, then exit before we get divide by 0 and such
    12. K = I:cross(J)
    13. RefFrame=transpose(matrix(I,J,K))
    14. #Finding the position vectors of the 3 points
    15. #in our new reference frame.
    16. A2 = vec()
    17. B2 = RefFrame*(B-A)
    18. C2 = RefFrame*(C-A)
    19.  
    20.  
    21. #Finding the circumcenter in local coords
    22. BisectX = B2:x()/2
    23. BisectC = C2/2
    24. DirC = vec(0,0,1):cross(C2):normalized()
    25. DistC = (BisectX-BisectC:x())/DirC:x()
    26. Circumcenter2 = BisectC + DistC*DirC
    27.  
    28. #Transforming results to world coords
    29. Circumcenter = A + transpose(RefFrame)*Circumcenter2
    30.  
    31.  
    32. #Let's be fancy. Illustrative Holograms!
    33. if(first()|duped()){createHolo(0) createHolo(1) createHolo(2)
    34. createHolo(3) createHolo(4) createHolo(5) createHolo(6)}
    35. if(Hologramscale){
    36. interval(250)
    37. Model = "box" Skin = 1
    38. Pos = entity():pos() + 20*entity():up()
    39. Holoframe=matrix(entity())*Hologramscale
    40. Scalingfactor = Hologramscale/11.867
    41. #A holoScale of 1 is 1 PHX unit, not 1 Gmod unit
    42.  
    43. #The triangle itself
    44. Temp = B2/2
    45. Temp = Pos + Holoframe*Temp
    46. holoPos(0,Temp)
    47. holoColor(0,vec(255,0,0),255)
    48. holoModel(0,Model,Skin)
    49. holoScale(0,(B2+vec(0,1,1))*Scalingfactor)
    50. holoAng(0,(Holoframe*B2):toAngle())
    51. Temp = BisectC
    52. Temp = Pos + Holoframe*Temp
    53. holoPos(1,Temp)
    54. holoModel(1,Model,Skin)
    55. holoColor(1,vec(0,255,0),255)
    56. holoScale(1,vec(C2:length(),1,1)*Scalingfactor)
    57. holoAng(1,(Holoframe*C2):toAngle())
    58. Temp = B2 + (C2-B2)/2
    59. Temp = Pos + Holoframe*Temp
    60. holoPos(2,Temp)
    61. holoModel(2,Model,Skin)
    62. holoColor(2,vec(0,0,255),255)
    63. holoScale(2,vec((C2-B2):length(),1,1)*Scalingfactor)
    64. holoAng(2,(Holoframe*(C2-B2)):toAngle())
    65.  
    66. #The circumcenter
    67. Temp = Circumcenter2
    68. Temp = Pos + Holoframe*Temp
    69. Dir = vec(0,1,0)
    70. holoPos(3,Temp)
    71. holoModel(3,Model,Skin)
    72. holoColor(3,vec(0,160,60),255)
    73. holoScale(3,vec(Dir:length(),1,1)*Scalingfactor)
    74. holoAng(3,(Holoframe*Dir):toAngle())
    75.  
    76. #The guidelines used to find the circumcenter
    77. if(Guidelines){
    78. Temp = (B2/2 + Circumcenter2)/2
    79. Temp = Pos + Holoframe*Temp
    80. Dir = vec(0,1,0)
    81. holoPos(4,Temp)
    82. holoModel(4,Model,Skin)
    83. holoColor(4,vec(0,160,60),255)
    84. holoScale(4,vec((Circumcenter2-B2/2):length(),1,1)*Scalingfactor)
    85. holoAng(4,(Holoframe*Dir):toAngle())
    86. Temp = (Circumcenter2 + BisectC)/2
    87. Temp = Pos + Holoframe*Temp
    88. Dir = DirC
    89. holoPos(5,Temp)
    90. holoModel(5,Model,Skin)
    91. holoColor(5,vec(0,160,60),255)
    92. holoScale(5,vec(DistC,1,1)*Scalingfactor)
    93. holoAng(5,(Holoframe*DirC):toAngle())
    94. }else{holoColor(4,vec(),0) holoColor(5,vec(),0)}
    95.  
    96. #The circumcircle
    97. if(Circumcircle){
    98. Radius = Circumcenter2:length()
    99. Temp = Circumcenter2
    100. Temp = Pos + Holoframe*Temp
    101. holoPos(6,Temp)
    102. holoModel(6,"cylinder",Skin)
    103. holoColor(6,vec(0,160,60),40)
    104. holoScale(6,vec(2*Radius,2*Radius,1)*Scalingfactor)
    105. holoAng(6,(Holoframe*vec(1,0,0)):toAngle())
    106. }else{holoColor(6,vec(),0)}
    107. }
    Attached Images
    Last edited by Magos Mechanicus; 05-11-2009 at 04:39 AM.
    I can wire anything directly into anything! I'm the Professor!
    -Professor Hubert Farnsworth

  6. #16
    Wire Illusionist


    Jimlad will become famous soon enough Jimlad's Avatar
    Join Date
    Dec 2008
    Posts
    861

    Default Re: [Extreme Math] Calculating a point equidistant from 3 others

    ooh that looks pretty neat, I'm going to have to check it out when I'm around later on. Yeah I didn't think the whole "other points" thing through, now that you mention it I'm pretty sure there aren't just two points, you'll have a line through the circumcentre, perpendicular to the plane that represents all the solutions. I think you'd need at least 4 points to start uniquely defining spheres.

    I'm going to have to check out those holograph functions, it makes me wonder whether you can't just use matrices to define them rather than setting a bunch of vectors/angles.

  7. #17
    Inactive Manaan is on a distinguished road Manaan's Avatar
    Join Date
    May 2009
    Location
    Texas
    Posts
    35

    Default Re: [Extreme Math] Calculating a point equidistant from 3 others

    I think you just destroyed my brain.
    This is way beyond me.
    [img]http://img9.imageshack.us/img9/4449/userbar742936.gif[/img]
    Unfortunately, I've been having some computer problems and can't get gmod to work any more. :(

  8. #18
    A Hologram
    McLovin is a jewel in the rough McLovin is a jewel in the rough McLovin is a jewel in the rough McLovin is a jewel in the rough McLovin's Avatar
    Join Date
    Sep 2008
    Location
    NY US
    Posts
    1,029
    Blog Entries
    2

    Default Re: [Extreme Math] Calculating a point equidistant from 3 others

    Quote Originally Posted by Magos Mechanicus View Post
    Thanks. I think that's right, though they may take some more pondering to find. They wouldn't be at the same distance as the circumcenter, would they? Also, using matrix*vector to transform coordinates was a lifesaver in the below stuff particularly because you can scale matrices by a scalar, so thanks for adding them.

    So today I finally got E2 holograms working and my first project to try and learn that was to illustrate the method in the above expression. The holo portion came out as about half of the gate afterwards, but it looks so cool I guess that's ok.

    I find it works best to take 3 GPSes and hook their vector outputs up to A,B and C, then jiggle them about relative to one another and watch the reaction. Use Hologramscale to scale the holograms - at 1 you should be able to line the GPSes up with the respective points (though it's tricky), at 0.5 the figure is at half size, at 2 it's at double size and so on. If Hologramscale is 0 the holograms are not used. By default it shows the triangle formed by the three input points - the red side goes from A (directly above the expression) to B, and the last point is C. The little cube marks the circumcenter. You can turn on Guidelines to see the two lines I use to find the circumcenter; it's found where they intersect. Each starts on the halfway mark of the respective triangle side and is normal to it. The last option is to turn on the circumcircle, just to show that it is indeed equidistant to the 3 points.

    e2 Code:
    1. @name Circumcenter
    2. @inputs A:vector B:vector C:vector
    3. @inputs Hologramscale Guidelines Circumcircle
    4. @outputs Circumcenter:vector C2:vector
    5. #Coordinate transformations
    6. #First things first:
    7. #Finding an orthonormal basis.
    8. I = (B-A):normalized()
    9. J = (C-A):normalized()
    10. J = (J-J:dot(I)*I):normalized()
    11. if(!J){exit()} #If A,B,C are on a line, then exit before we get divide by 0 and such
    12. K = I:cross(J)
    13. RefFrame=transpose(matrix(I,J,K))
    14. #Finding the position vectors of the 3 points
    15. #in our new reference frame.
    16. A2 = vec()
    17. B2 = RefFrame*(B-A)
    18. C2 = RefFrame*(C-A)
    19.  
    20.  
    21. #Finding the circumcenter in local coords
    22. BisectX = B2:x()/2
    23. BisectC = C2/2
    24. DirC = vec(0,0,1):cross(C2):normalized()
    25. DistC = (BisectX-BisectC:x())/DirC:x()
    26. Circumcenter2 = BisectC + DistC*DirC
    27.  
    28. #Transforming results to world coords
    29. Circumcenter = A + transpose(RefFrame)*Circumcenter2
    30.  
    31.  
    32. #Let's be fancy. Illustrative Holograms!
    33. if(first()|duped()){createHolo(0) createHolo(1) createHolo(2)
    34. createHolo(3) createHolo(4) createHolo(5) createHolo(6)}
    35. if(Hologramscale){
    36. interval(250)
    37. Model = "box" Skin = 1
    38. Pos = entity():pos() + 20*entity():up()
    39. Holoframe=matrix(entity())*Hologramscale
    40. Scalingfactor = Hologramscale/11.867
    41. #A holoScale of 1 is 1 PHX unit, not 1 Gmod unit
    42.  
    43. #The triangle itself
    44. Temp = B2/2
    45. Temp = Pos + Holoframe*Temp
    46. holoPos(0,Temp)
    47. holoColor(0,vec(255,0,0),255)
    48. holoModel(0,Model,Skin)
    49. holoScale(0,(B2+vec(0,1,1))*Scalingfactor)
    50. holoAng(0,(Holoframe*B2):toAngle())
    51. Temp = BisectC
    52. Temp = Pos + Holoframe*Temp
    53. holoPos(1,Temp)
    54. holoModel(1,Model,Skin)
    55. holoColor(1,vec(0,255,0),255)
    56. holoScale(1,vec(C2:length(),1,1)*Scalingfactor)
    57. holoAng(1,(Holoframe*C2):toAngle())
    58. Temp = B2 + (C2-B2)/2
    59. Temp = Pos + Holoframe*Temp
    60. holoPos(2,Temp)
    61. holoModel(2,Model,Skin)
    62. holoColor(2,vec(0,0,255),255)
    63. holoScale(2,vec((C2-B2):length(),1,1)*Scalingfactor)
    64. holoAng(2,(Holoframe*(C2-B2)):toAngle())
    65.  
    66. #The circumcenter
    67. Temp = Circumcenter2
    68. Temp = Pos + Holoframe*Temp
    69. Dir = vec(0,1,0)
    70. holoPos(3,Temp)
    71. holoModel(3,Model,Skin)
    72. holoColor(3,vec(0,160,60),255)
    73. holoScale(3,vec(Dir:length(),1,1)*Scalingfactor)
    74. holoAng(3,(Holoframe*Dir):toAngle())
    75.  
    76. #The guidelines used to find the circumcenter
    77. if(Guidelines){
    78. Temp = (B2/2 + Circumcenter2)/2
    79. Temp = Pos + Holoframe*Temp
    80. Dir = vec(0,1,0)
    81. holoPos(4,Temp)
    82. holoModel(4,Model,Skin)
    83. holoColor(4,vec(0,160,60),255)
    84. holoScale(4,vec((Circumcenter2-B2/2):length(),1,1)*Scalingfactor)
    85. holoAng(4,(Holoframe*Dir):toAngle())
    86. Temp = (Circumcenter2 + BisectC)/2
    87. Temp = Pos + Holoframe*Temp
    88. Dir = DirC
    89. holoPos(5,Temp)
    90. holoModel(5,Model,Skin)
    91. holoColor(5,vec(0,160,60),255)
    92. holoScale(5,vec(DistC,1,1)*Scalingfactor)
    93. holoAng(5,(Holoframe*DirC):toAngle())
    94. }else{holoColor(4,vec(),0) holoColor(5,vec(),0)}
    95.  
    96. #The circumcircle
    97. if(Circumcircle){
    98. Radius = Circumcenter2:length()
    99. Temp = Circumcenter2
    100. Temp = Pos + Holoframe*Temp
    101. holoPos(6,Temp)
    102. holoModel(6,"cylinder",Skin)
    103. holoColor(6,vec(0,160,60),40)
    104. holoScale(6,vec(2*Radius,2*Radius,1)*Scalingfactor)
    105. holoAng(6,(Holoframe*vec(1,0,0)):toAngle())
    106. }else{holoColor(6,vec(),0)}
    107. }
    Some one is making something useful other then a holo jizz contraption!
    Filipe - you never know what ends up in your love hole
    Poonage - It's not a disorder, it can be solved
    Drunkie - vista was on the trail of complete beauty and perfection
    Omicron - cable management is for losers, and people who know what they're doing
    Drunkie - me and solece have tickets to go see justin bieber, i'm looking forward to it
    JatGoodwin - I don't normally suck dick, but when I do they call me immibis
    Drunkie - THERE IS SIMPLY NOT ENOUGH DICKS
    JatGoodwin - stand back, im going to do science

  9. #19
    Master of Mars


    Magos Mechanicus will become famous soon enough Magos Mechanicus will become famous soon enough Magos Mechanicus's Avatar
    Join Date
    May 2008
    Posts
    834

    Default Warning: May contain EXTREME MATH!

    Got to thinking more about this problem, and I realized that assuming the equidistant point of 4 given points is on the line through the circumcenter of the first 3, you could instead of doing any geometry use the condition of equidistance to solve for z algebraically. I threw it into Maple and the z^2 term cancels so there's no bothering with the whole 0-2 solutions business. Encouraged by this, I tested it in game. The expression reports that it is indeed equidistant when I use V:length(), but the sphere hologram is apparently a bit too coarse-grained to show it very well.

    Indeed, there's a lot of stuff you can do with the holograms other than create randomly floating stuff. They're really fun to use, and I think I'm going to go for a wall clock soon.
    Attached Images
    Attached Files
    Last edited by Magos Mechanicus; 05-15-2009 at 06:39 AM.
    I can wire anything directly into anything! I'm the Professor!
    -Professor Hubert Farnsworth

  10. #20
    Newbie Programmer ZeikJT will become famous soon enough ZeikJT's Avatar
    Join Date
    Dec 2008
    Location
    California
    Posts
    1,394

    Default Re: [Extreme Math] Calculating a point equidistant from 3 others

    If you want a smoother sphere use a bigger number.
    sphere is the clunkiest.
    sphere2 is more smooth.
    sphere3 is the most smooth.

    I left the default as the clunkiest so people don't spam the most intensive one without reason.
    Against stupidity the Gods themselves contend in vain.
    -Friedrich Schiller

    The flame puts me in the mood to "Do it!".
    -Dart, Legend of Dragoon

+ Reply to Thread
Page 2 of 3 FirstFirst 1 2 3 LastLast

Similar Threads

  1. Help on calculating 3d distances
    By lucasmontec in forum Technical Support
    Replies: 12
    Last Post: 03-09-2009, 11:48 AM
  2. Peggle Extreme: Epic Win
    By IEF015 in forum Off-Topic
    Replies: 5
    Last Post: 06-22-2008, 03:09 PM
  3. Making a exprssion math into cpu math
    By Ronin in forum CPU, GPU, and Hi-speed
    Replies: 5
    Last Post: 06-03-2008, 06:09 PM
  4. Calculating bearing?
    By thesage1014 in forum Technical Support
    Replies: 7
    Last Post: 08-19-2007, 10:32 PM
  5. Extreme low poly nano gate
    By cheeze in forum Developer's Showcase
    Replies: 11
    Last Post: 06-26-2007, 07:08 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
proceed-collector
proceed-collector
proceed-collector
proceed-collector
linguistic-parrots
linguistic-parrots
linguistic-parrots
linguistic-parrots