We have an exciting announcement about badges coming in May 2025. Until then, we will temporarily stop issuing new badges for course completions and certifications. However, all completions will be recorded and fulfilled after May 2025.
General

General

Discovery SpaceClaim – Scripting – Calculating distance between local coordinate systems

    • FAQFAQ
      Participant

      Script for calculating distance between 2 local coordinate systems:

      import math

      part = GetRootPart()

      #access local coordinate systems
      temp1 = part.CoordinateSystems[0]
      temp2 = part.CoordinateSystems[1]

      #access origin of coordinate systems
      coord1 = temp1.Frame.Origin
      coord2 = temp2.Frame.Origin

      #note – the values of origin are returned in Meter units

      #calculate distance between 2 coordinate systems

      x_dist = coord2[0]-coord1[0]
      y_dist = coord2[1]-coord1[1]
      z_dist = coord2[2]-coord1[2]

      dist = math.sqrt((x_dist**2)+(y_dist**2)+(z_dist**2))

      print dist

       

      Script for calculating distance between any local coordinate system and world origin:

      import math

      part = GetRootPart()

      #access local coordinate system
      temp = part.CoordinateSystems[0]

      #access origin of coordinate system
      a = temp.Frame.Origin
      print a

      #note – the values of origin are returned in Meter units

      #calculate distance from global origin
      dist = math.sqrt((a[0]*a[0])+(a[1]*a[1])+(a[2]*a[2]))
      print dist