How do I get the distance between 2 3d points?

BlitzMax Forums/MiniB3D Module/How do I get the distance between 2 3d points?

Sanctus(Posted 2007) [#1]
Hi!
How do I get the distance between 2 3d points?(they both have x,y,z coords)
I know how to use it on a 2d place with phitagoras but in 3d??


Who was John Galt?(Posted 2007) [#2]
Similar to 2D. Add the squares of the distances in x, y, z. Then take the square root of the result.


H&K(Posted 2007) [#3]
Similar to 2D. Add the squares of the difference in distances in x, y, z. Then take the square root of the result.

(Dx*Dx+Dy*Dy+Dz*Dz)^.5


semar(Posted 2007) [#4]
Or create two temporary pivots at the two 3D locations, and then use EntityDistance.

Sergio.


Rob Farley(Posted 2007) [#5]
I'm with Semar on this one, although I usually create a couple of pivots as globals at the top of my code p1 and p2 and just use them all over the place. Then you don't need to create and kill entities all the time.


Sanctus(Posted 2007) [#6]
Thx Nomen luni and H&K but I don't really get it with the "^.5" part... I'm 9th grade and I don't remeber doing this at school.
Here is how I did it
Local dist:Float = Sqr((px-vx)*(px-vx)+(py-vy)*(py-vy)+(pz-vz)*(pz-vz))

And semar and ><)))º> thx but I will do this proces a lot of times so your ideea will slow down the program


fredborg(Posted 2007) [#7]
a^0.5 = Sqr(a)

The only difference is that a^0.5 is a wee bit slower on most processors.


Sanctus(Posted 2007) [#8]
Okay... I got it to work... but now I have a new problem...
If rise = 1 Or low = 1
	'DebugStop
	Local pick:Tentity = CameraPick(cam.cam,EventX(),EventY())
	If Not pick = 0
	Local px:Float = PickedX()
	Local py:Float = PickedY()
	Local pz:Float = PickedZ()
	Local pnx:Float = PickedNX()
	Local pny:Float = PickedNY()
	Local pnz:Float = PickedNZ()
	Local ptriangle:Int = PickedTriangle()
	Local psurface:Tsurface = PickedSurface()
	Local pentity:tentity = PickedEntity()
	Local p1:Tpivot = CreatePivot()
	PositionEntity(p1,px,py,pz)
	Local p2:Tpivot = CreatePivot()
	For Local i:Int = 1 To psurface.no_verts
		Local vx:Float = VertexX(psurface,i)
		Local vy:Float = VertexY(psurface,i)
		Local vz:Float = VertexZ(psurface,i)
		PositionEntity(p2,vx,vy,vz)
		Local dist:Float = EntityDistance(p1,p2)
		If dist <= Float(GadgetText(ModifyTerrainWnd_TextField_Amount))
			If low = 1
				MoveVertex(psurface,i,0,-0.1,0)
			ElseIf rise = 1
				MoveVertex(psurface,i,0,0.1,0)
			EndIf
		EndIf
		Next
	EndIf
EndIf

This inside of a EVEN_MOUSEDOWN
th ideea is that when I click on a plane the vertices that are in a set amount of distance move down or up... I ckeck for every vertice the distance between it and the pickedx,y,z... the vertices do move up or down... but in some cases some vertices that are at a bigger distance and at the margin of the plane(important) also move up or down