Skip to content


# DistanceBetweenPoints

VTKEx/Python/SimpleOperations/DistanceBetweenPoints

### Description

This example finds the squared distance and the Euclidean distance between two 3D points.

Other languages

See (Cxx), (Java), (CSharp)

Question

If you have a simple question about this example contact us at VTKExProject If your question is more complex and may require extended discussion, please use the VTK Discourse Forum

### Code

DistanceBetweenPoints.py

    from __future__ import print_function

    import math

    import vtk

    p0 = (0, 0, 0)
    p1 = (1, 1, 1)

    distSquared = vtk.vtkMath.Distance2BetweenPoints(p0, p1)

    dist = math.sqrt(distSquared)

    print("p0 = ", p0)
    print("p1 = ", p1)
    print("distance squared = ", distSquared)
    print("distance = ", dist)