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

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

  1. #11
    Wire Sofaking Jimlad's Avatar
    Join Date
    Dec 2008
    Posts
    941

    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's Avatar
    Join Date
    May 2008
    Posts
    852

    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).

    [highlight=e2]
    @name Circumcenter
    @inputs A:vector B:vector C:vector
    @outputs Circumcenter:vector
    #Coordinate transformations
    #First things first:
    #Finding an orthonormal basis.
    I = (B-A):normalized()
    J = (C-A):normalized()
    J = (J-J:dot(I)*I):normalized()
    if(!J){exit()} #If A,B,C are on a line, then exit before we get divide by 0 and such
    K = J:cross(I)
    RefFrame=transpose(matrix(I,J,K))
    #Finding the position vectors of the 3 points
    #in our new reference frame.
    A2 = vec()
    B2 = RefFrame*(B-A)
    C2 = RefFrame*(C-A)

    #Finding the circumcenter in local coords
    BisectX = B2:x()/2
    BisectC = C2/2
    DirC = vec(0,0,1):cross(C2):normalized()
    DistC = (BisectX-BisectC:x())/DirC:x()
    Circumcenter2 = BisectC + DistC*DirC

    #Transforming results to world coords
    Circumcenter = A + RefFrame^-1*Circumcenter2

    [/highlight]
    Last edited by Magos Mechanicus; 05-10-2009 at 02: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-'s Avatar
    Join Date
    Feb 2009
    Location
    Behind you with a very sharp knife.
    Posts
    2,466

    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).

    [highlight=e2]@name Circumcenter
    @inputs A:vector B:vector C:vector
    @outputs Circumcenter:vector
    #Coordinate transformations
    #First things first:
    #Finding an orthonormal basis.
    I = (B-A):normalized()
    J = (C-A):normalized()
    J = (J-J:dot(I)*I):normalized()
    K = J:cross(I)
    RefFrame=transpose(matrix(I,J,K))
    #Finding the position vectors of the 3 points
    #in our new reference frame.
    A2 = vec()
    B2 = RefFrame*(B-A)
    C2 = RefFrame*(C-A)

    #Finding the circumcenter in local coords
    BisectX = B2:x()/2
    BisectC = C2/2
    DirC = vec(0,0,1):cross(C2):normalized()
    DistC = (BisectX-BisectC:x())/DirC:x()
    Circumcenter2 = BisectC + DistC*DirC

    #Transforming results to world coords
    Circumcenter = A + RefFrame^-1*Circumcenter2
    [/highlight]
    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

  4. #14
    Wire Sofaking Jimlad's Avatar
    Join Date
    Dec 2008
    Posts
    941

    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's Avatar
    Join Date
    May 2008
    Posts
    852

    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.

    [highlight=e2]
    @name Circumcenter
    @inputs A:vector B:vector C:vector
    @inputs Hologramscale Guidelines Circumcircle
    @outputs Circumcenter:vector C2:vector
    #Coordinate transformations
    #First things first:
    #Finding an orthonormal basis.
    I = (B-A):normalized()
    J = (C-A):normalized()
    J = (J-J:dot(I)*I):normalized()
    if(!J){exit()} #If A,B,C are on a line, then exit before we get divide by 0 and such
    K = I:cross(J)
    RefFrame=transpose(matrix(I,J,K))
    #Finding the position vectors of the 3 points
    #in our new reference frame.
    A2 = vec()
    B2 = RefFrame*(B-A)
    C2 = RefFrame*(C-A)


    #Finding the circumcenter in local coords
    BisectX = B2:x()/2
    BisectC = C2/2
    DirC = vec(0,0,1):cross(C2):normalized()
    DistC = (BisectX-BisectC:x())/DirC:x()
    Circumcenter2 = BisectC + DistC*DirC

    #Transforming results to world coords
    Circumcenter = A + transpose(RefFrame)*Circumcenter2


    #Let's be fancy. Illustrative Holograms!
    if(first()|duped()){createHolo(0) createHolo(1) createHolo(2)
    createHolo(3) createHolo(4) createHolo(5) createHolo(6)}
    if(Hologramscale){
    interval(250)
    Model = "box" Skin = 1
    Pos = entity()os() + 20*entity():up()
    Holoframe=matrix(entity())*Hologramscale
    Scalingfactor = Hologramscale/11.867
    #A holoScale of 1 is 1 PHX unit, not 1 Gmod unit

    #The triangle itself
    Temp = B2/2
    Temp = Pos + Holoframe*Temp
    holoPos(0,Temp)
    holoColor(0,vec(255,0,0),255)
    holoModel(0,Model,Skin)
    holoScale(0,(B2+vec(0,1,1))*Scalingfactor)
    holoAng(0,(Holoframe*B2):toAngle())
    Temp = BisectC
    Temp = Pos + Holoframe*Temp
    holoPos(1,Temp)
    holoModel(1,Model,Skin)
    holoColor(1,vec(0,255,0),255)
    holoScale(1,vec(C2:length(),1,1)*Scalingfactor)
    holoAng(1,(Holoframe*C2):toAngle())
    Temp = B2 + (C2-B2)/2
    Temp = Pos + Holoframe*Temp
    holoPos(2,Temp)
    holoModel(2,Model,Skin)
    holoColor(2,vec(0,0,255),255)
    holoScale(2,vec((C2-B2):length(),1,1)*Scalingfactor)
    holoAng(2,(Holoframe*(C2-B2)):toAngle())

    #The circumcenter
    Temp = Circumcenter2
    Temp = Pos + Holoframe*Temp
    Dir = vec(0,1,0)
    holoPos(3,Temp)
    holoModel(3,Model,Skin)
    holoColor(3,vec(0,160,60),255)
    holoScale(3,vec(Dir:length(),1,1)*Scalingfactor)
    holoAng(3,(Holoframe*Dir):toAngle())

    #The guidelines used to find the circumcenter
    if(Guidelines){
    Temp = (B2/2 + Circumcenter2)/2
    Temp = Pos + Holoframe*Temp
    Dir = vec(0,1,0)
    holoPos(4,Temp)
    holoModel(4,Model,Skin)
    holoColor(4,vec(0,160,60),255)
    holoScale(4,vec((Circumcenter2-B2/2):length(),1,1)*Scalingfactor)
    holoAng(4,(Holoframe*Dir):toAngle())
    Temp = (Circumcenter2 + BisectC)/2
    Temp = Pos + Holoframe*Temp
    Dir = DirC
    holoPos(5,Temp)
    holoModel(5,Model,Skin)
    holoColor(5,vec(0,160,60),255)
    holoScale(5,vec(DistC,1,1)*Scalingfactor)
    holoAng(5,(Holoframe*DirC):toAngle())
    }else{holoColor(4,vec(),0) holoColor(5,vec(),0)}

    #The circumcircle
    if(Circumcircle){
    Radius = Circumcenter2:length()
    Temp = Circumcenter2
    Temp = Pos + Holoframe*Temp
    holoPos(6,Temp)
    holoModel(6,"cylinder",Skin)
    holoColor(6,vec(0,160,60),40)
    holoScale(6,vec(2*Radius,2*Radius,1)*Scalingfactor )
    holoAng(6,(Holoframe*vec(1,0,0)):toAngle())
    }else{holoColor(6,vec(),0)}
    }

    [/highlight]
    Attached Thumbnails Attached Thumbnails [Extreme Math] Calculating a point equidistant from 3 others-gm_construct0005.jpg   [Extreme Math] Calculating a point equidistant from 3 others-gm_construct0006.jpg   [Extreme Math] Calculating a point equidistant from 3 others-gm_construct0007.jpg  
    Last edited by Magos Mechanicus; 05-11-2009 at 05:39 AM.
    I can wire anything directly into anything! I'm the Professor!
    -Professor Hubert Farnsworth

  6. #16
    Wire Sofaking Jimlad's Avatar
    Join Date
    Dec 2008
    Posts
    941

    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
    Wire Amateur 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.

    Unfortunately, I've been having some computer problems and can't get gmod to work any more.

  8. #18
    ◕␣◕ McLovin's Avatar
    Join Date
    Sep 2008
    Location
    Batman, Turkey
    Posts
    2,333
    Blog Entries
    3

    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.

    [highlight=e2]
    @name Circumcenter
    @inputs A:vector B:vector C:vector
    @inputs Hologramscale Guidelines Circumcircle
    @outputs Circumcenter:vector C2:vector
    #Coordinate transformations
    #First things first:
    #Finding an orthonormal basis.
    I = (B-A):normalized()
    J = (C-A):normalized()
    J = (J-J:dot(I)*I):normalized()
    if(!J){exit()} #If A,B,C are on a line, then exit before we get divide by 0 and such
    K = I:cross(J)
    RefFrame=transpose(matrix(I,J,K))
    #Finding the position vectors of the 3 points
    #in our new reference frame.
    A2 = vec()
    B2 = RefFrame*(B-A)
    C2 = RefFrame*(C-A)


    #Finding the circumcenter in local coords
    BisectX = B2:x()/2
    BisectC = C2/2
    DirC = vec(0,0,1):cross(C2):normalized()
    DistC = (BisectX-BisectC:x())/DirC:x()
    Circumcenter2 = BisectC + DistC*DirC

    #Transforming results to world coords
    Circumcenter = A + transpose(RefFrame)*Circumcenter2


    #Let's be fancy. Illustrative Holograms!
    if(first()|duped()){createHolo(0) createHolo(1) createHolo(2)
    createHolo(3) createHolo(4) createHolo(5) createHolo(6)}
    if(Hologramscale){
    interval(250)
    Model = "box" Skin = 1
    Pos = entity()os() + 20*entity():up()
    Holoframe=matrix(entity())*Hologramscale
    Scalingfactor = Hologramscale/11.867
    #A holoScale of 1 is 1 PHX unit, not 1 Gmod unit

    #The triangle itself
    Temp = B2/2
    Temp = Pos + Holoframe*Temp
    holoPos(0,Temp)
    holoColor(0,vec(255,0,0),255)
    holoModel(0,Model,Skin)
    holoScale(0,(B2+vec(0,1,1))*Scalingfactor)
    holoAng(0,(Holoframe*B2):toAngle())
    Temp = BisectC
    Temp = Pos + Holoframe*Temp
    holoPos(1,Temp)
    holoModel(1,Model,Skin)
    holoColor(1,vec(0,255,0),255)
    holoScale(1,vec(C2:length(),1,1)*Scalingfactor)
    holoAng(1,(Holoframe*C2):toAngle())
    Temp = B2 + (C2-B2)/2
    Temp = Pos + Holoframe*Temp
    holoPos(2,Temp)
    holoModel(2,Model,Skin)
    holoColor(2,vec(0,0,255),255)
    holoScale(2,vec((C2-B2):length(),1,1)*Scalingfactor)
    holoAng(2,(Holoframe*(C2-B2)):toAngle())

    #The circumcenter
    Temp = Circumcenter2
    Temp = Pos + Holoframe*Temp
    Dir = vec(0,1,0)
    holoPos(3,Temp)
    holoModel(3,Model,Skin)
    holoColor(3,vec(0,160,60),255)
    holoScale(3,vec(Dir:length(),1,1)*Scalingfactor)
    holoAng(3,(Holoframe*Dir):toAngle())

    #The guidelines used to find the circumcenter
    if(Guidelines){
    Temp = (B2/2 + Circumcenter2)/2
    Temp = Pos + Holoframe*Temp
    Dir = vec(0,1,0)
    holoPos(4,Temp)
    holoModel(4,Model,Skin)
    holoColor(4,vec(0,160,60),255)
    holoScale(4,vec((Circumcenter2-B2/2):length(),1,1)*Scalingfactor)
    holoAng(4,(Holoframe*Dir):toAngle())
    Temp = (Circumcenter2 + BisectC)/2
    Temp = Pos + Holoframe*Temp
    Dir = DirC
    holoPos(5,Temp)
    holoModel(5,Model,Skin)
    holoColor(5,vec(0,160,60),255)
    holoScale(5,vec(DistC,1,1)*Scalingfactor)
    holoAng(5,(Holoframe*DirC):toAngle())
    }else{holoColor(4,vec(),0) holoColor(5,vec(),0)}

    #The circumcircle
    if(Circumcircle){
    Radius = Circumcenter2:length()
    Temp = Circumcenter2
    Temp = Pos + Holoframe*Temp
    holoPos(6,Temp)
    holoModel(6,"cylinder",Skin)
    holoColor(6,vec(0,160,60),40)
    holoScale(6,vec(2*Radius,2*Radius,1)*Scalingfactor )
    holoAng(6,(Holoframe*vec(1,0,0)):toAngle())
    }else{holoColor(6,vec(),0)}
    }

    [/highlight]
    Some one is making something useful other then a holo jizz contraption!
    Anticept - HP you are terrible at trolling. Always have been. Leave it up to the pros like Jat.
    Black Phoenix - Actually cunt goes into bullshit. Bullshit does not fit in cunt.
    Drunkie - Logically, Jat Goodwin must be a fist pumping guido.

  9. #19
    Master of Mars Magos Mechanicus's Avatar
    Join Date
    May 2008
    Posts
    852

    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 Thumbnails Attached Thumbnails [Extreme Math] Calculating a point equidistant from 3 others-gm_construct0009.jpg   [Extreme Math] Calculating a point equidistant from 3 others-gm_construct0010.jpg   [Extreme Math] Calculating a point equidistant from 3 others-gm_construct0011.jpg  
    Attached Files Attached Files
    Last edited by Magos Mechanicus; 05-15-2009 at 07:39 AM.
    I can wire anything directly into anything! I'm the Professor!
    -Professor Hubert Farnsworth

  10. #20
    Wire Sofaking ZeikJT's Avatar
    Join Date
    Dec 2008
    Location
    California
    Posts
    1,391

    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 123 LastLast

Similar Threads

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