VTK/Examples/Cxx/SimpleOperations/DistanceBetweenPoints

From KitwarePublic

Jump to: navigation, search

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

Click here to download this example.

DistanceBetweenPoints.cxx

#include <vtkMath.h>
 
int main(int, char *[])
{
  // Create two points.
  double p0[3] = {0.0, 0.0, 0.0};
  double p1[3] = {1.0, 1.0, 1.0};
 
  // Find the squared distance between the points.
  double squaredDistance = vtkMath::Distance2BetweenPoints(p0, p1);
 
  // Take the square root to get the Euclidean distance between the points.
  double distance = sqrt(squaredDistance);
 
  // Output the results.
  std::cout << "SquaredDistance = " << squaredDistance << std::endl;
  std::cout << "Distance = " << distance << std::endl;
 
  return EXIT_SUCCESS;
}

CMakeLists.txt

cmake_minimum_required(VERSION 2.8)
 
PROJECT(DistanceBetweenPoints)
 
find_package(VTK REQUIRED)
include(${VTK_USE_FILE})
 
if (APPLE)
  add_executable(DistanceBetweenPoints MACOSX_BUNDLE DistanceBetweenPoints.cxx)
else()
  add_executable(DistanceBetweenPoints DistanceBetweenPoints.cxx)
endif()
 
if(VTK_LIBRARIES)
  target_link_libraries(DistanceBetweenPoints ${VTK_LIBRARIES})
else()
  target_link_libraries(DistanceBetweenPoints vtkHybrid )
endif()
Personal tools