VEXLib Help

Translation1d Class Documentation

Overview

The Translation1d class represents a one-dimensional translation, allowing for the manipulation of a scalar magnitude along a single dimension. This class provides methods for arithmetic operations, unit conversions, and utility functions to work with the magnitude in various units.

Importing the Class

To use the Translation1d class, you need to import the required module from the VEXLib library:

from VEXLib.Geometry.Translation1d import Translation1d

Key Functionalities

Initialization

While you can initialize a Translation1d object directly with a magnitude in meters, it is best practice to be explicit and use the provided class methods such as from_meters, from_centimeters, from_inches, and from_feet to reduce errors in units:

# Best practice for initialization translation = Translation1d.from_inches(39.37)

Arithmetic Operations

The class supports addition, subtraction, multiplication, and division:

# Addition result = translation1 + translation2 # Multiplication by a scalar scaled = translation * 2

Unit Conversions

You can convert the magnitude to various units:

# Convert to centimeters centimeters = translation.to_centimeters() # Convert to feet feet = translation.to_feet()

Utility Methods

Inverse

Calculate the unary inverse of a Translation1d object:

inverse_translation = translation.inverse() # Inverts the magnitude

Usage Examples

Creating a Translation1d Object

Best practice for creating a Translation1d object:

translation = Translation1d.from_inches(39.37) print(translation) # Output: 1.0m

Adding Two Translation1d Objects

translation1 = Translation1d.from_meters(3) translation2 = Translation1d.from_meters(4) result = translation1 + translation2 print(result) # Output: 7.0m

Converting Units

translation = Translation1d.from_inches(39.37) print(translation.to_meters()) # Output: 1.0 print(translation.to_centimeters()) # Output: 100.0 print(translation.to_inches()) # Output: 39.37 print(translation.to_feet()) # Output: 3.28084

This documentation covers the essential parts of the Translation1d class and highlights best practices to avoid errors when dealing with unit conversions.

21 April 2025