code: def _apply_affine_to_points(
      points: torch.Tensor,
      affine: torch.Tensor,
      include_shift: bool = True,
  ) -> torch.Tensor:
      """
      This internal function applies affine matrices to the point coordinate
  
      Args:
          points: point coordinates, Nx2 or Nx3 torch tensor or ndarray, representing [x, y] or [x, y, z]
          affine: affine matrix to be applied to the point coordinates, sized (spatial_dims+1,spatial_dims+1)
          include_shift: default True, whether the function apply translation (shift) in the affine transform
  
      Returns:
          transformed point coordinates, with same data type as ``points``, does not share memory with ``points``
      """
  
      spatial_dims = get_spatial_dims(points=points)
  
      # compute new points
      if include_shift:
          # append 1 to form Nx(spatial_dims+1) vector, then transpose
          points_affine = torch.cat(
              [
                  points,
                  torch.ones(
                      points.shape[0],
                      1,
                      device=points.device,
                      dtype=points.dtype,
                  ),
              ],
              dim=1,
          ).transpose(0, 1)
          # apply affine
          points_affine = torch.matmul(affine, points_affine)
          # remove appended 1 and transpose back
          points_affine = points_affine[:spatial_dims, :].transpose(
              0, 1
          )
      else:
          points_affine = points.transpose(0, 1)
          points_affine = torch.matmul(
              affine[:spatial_dims, :spatial_dims], points_affine
          )
          points_affine = points_affine.transpose(0, 1)
  
      return points_affine
  
imports: from __future__ import annotations
  from collections.abc import Sequence
  from copy import deepcopy
  import numpy
  import torch
  from monai.config.type_definitions import DtypeLike, NdarrayOrTensor, NdarrayTensor
  from monai.data.box_utils import COMPUTE_DTYPE, TO_REMOVE, get_spatial_dims
  from monai.transforms import Resize
  from monai.transforms.utils import create_scale
  from monai.utils import look_up_option
  from monai.utils.misc import ensure_tuple, ensure_tuple_rep
  from monai.utils.type_conversion import convert_data_type, convert_to_dst_type
label_desc: Use image node_id 1 for calling a global function with example usage: _apply_affine_to_points(points, affine, include_shift) and returns: points_affine