Roboid Control for Python
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | List of all members
Polar Class Reference

Detailed Description

A polar 2D vector.

Inheritance diagram for Polar:
Spherical Spherical

Public Member Functions

 __init__ (self, float distance, Angle angle)
 Create a new polar vector.
 
 Degrees (float distance, float degrees)
 Create a polar vector without using the Angle type.
 
 Radians (float distance, float radians)
 Create polar vector without using the Angle type.
 
Vector2 ToVector2 (self)
 Convert the polar coordinate to a Vector2 coordinate.
 
bool __eq__ (self, other)
 Check if this vector is equal to the given vector.
 
float Magnitude (self)
 
 Normalized (self)
 
 __neg__ (self)
 Negate the vector.
 
 __sub__ (self, other)
 Subtract a polar vector from this vector.
 
 __add__ (self, other)
 Add a polar vector to this vector.
 
 __mul__ (self, factor)
 Scale the vector uniformly up.
 
 __truediv__ (self, factor)
 Scale the vector uniformly down.
 
 Lerp (v1, v2, float f)
 Lerp (linear interpolation) between two vectors.
 
 __init__ (self, float distance, Angle angle)
 Create a new polar vector.
 
 Degrees (float distance, float degrees)
 Create a polar vector without using the Angle type.
 
 Radians (float distance, float radians)
 Create polar vector without using the Angle type.
 
Vector2 ToVector2 (self)
 Convert the polar coordinate to a Vector2 coordinate.
 
bool __eq__ (self, other)
 Check if this vector is equal to the given vector.
 
 isclose (self, other, rel_tol=1e-9, abs_tol=1e-8)
 
float Magnitude (self)
 
 Normalized (self)
 
 __neg__ (self)
 Negate the vector.
 
 __sub__ (self, other)
 Subtract a polar vector from this vector.
 
 __add__ (self, other)
 Add a polar vector to this vector.
 
 __mul__ (self, factor)
 Scale the vector uniformly up.
 
 __truediv__ (self, factor)
 Scale the vector uniformly down.
 
 Lerp (v1, v2, float f)
 Lerp (linear interpolation) between two vectors.
 

Static Public Member Functions

 FromVector2 (Vector2 v)
 Create a polar coordinate from a Vector2 coordinate.
 
float Distance (v1, v2)
 Calculate the distance between two spherical coordinates.
 
Angle Angle (v1, v2)
 Calculate the unsigned angle between two spherical vectors.
 
Angle SignedAngle (v1, v2)
 Calculate the unsigned angle between two spherical vectors.
 
 FromVector2 (Vector2 v)
 Create a polar coordinate from a Vector2 coordinate.
 
float Distance (v1, v2)
 Calculate the distance between two spherical coordinates.
 
Angle Angle (v1, v2)
 Calculate the unsigned angle between two spherical vectors.
 
Angle SignedAngle (v1, v2)
 Calculate the unsigned angle between two spherical vectors.
 

Public Attributes

 distance
 The direction of the vector.
 
 direction
 

Static Public Attributes

 zero
 

Constructor & Destructor Documentation

◆ __init__() [1/2]

__init__ (   self,
float  distance,
Angle  angle 
)

Create a new polar vector.

Parameters
distanceThe length of the vector
angleThe direction of the angle

Reimplemented in Spherical, and Spherical.

◆ __init__() [2/2]

__init__ (   self,
float  distance,
Angle  angle 
)

Create a new polar vector.

Parameters
distanceThe length of the vector
angleThe direction of the angle

Reimplemented in Spherical, and Spherical.

Member Function Documentation

◆ Degrees() [1/2]

Degrees ( float  distance,
float  degrees 
)

Create a polar vector without using the Angle type.

All given angles are in degrees

Parameters
distanceThe distance in meters
horizontalThe angle in degrees
Returns
The polar vector

Reimplemented in Spherical, and Spherical.

◆ Radians() [1/2]

Radians ( float  distance,
float  radians 
)

Create polar vector without using the Angle type.

All given angles are in radians

Parameters
distanceThe distance in meters
horizontalThe horizontal angle in radians
verticalThe vertical angle in radians
Returns
The polar vector

Reimplemented in Spherical, and Spherical.

◆ FromVector2() [1/2]

FromVector2 ( Vector2  v)
static

Create a polar coordinate from a Vector2 coordinate.

Parameters
vThe vector coordinate
Returns
The polar coordinate

◆ ToVector2() [1/2]

Vector2 ToVector2 (   self)

Convert the polar coordinate to a Vector2 coordinate.

Returns
The vector coordinate

◆ __eq__() [1/2]

bool __eq__ (   self,
  other 
)

Check if this vector is equal to the given vector.

Parameters
vThe vector to check against
Returns
true if it is identical to the given vector
Note
This uses float comparison to check equality which may have strange effects. Equality on floats should be avoided.

Reimplemented in Spherical, and Spherical.

◆ __neg__() [1/2]

__neg__ (   self)

Negate the vector.

Returns
The negated vector This will negate the direction. Distance will stay the same.

Reimplemented in Spherical, and Spherical.

◆ __sub__() [1/2]

__sub__ (   self,
  other 
)

Subtract a polar vector from this vector.

Parameters
otherThe vector to subtract
Returns
The result of the subtraction

Reimplemented in Spherical, and Spherical.

◆ __add__() [1/2]

__add__ (   self,
  other 
)

Add a polar vector to this vector.

Parameters
otherThe vector to add
Returns
The result of the addition

Reimplemented in Spherical, and Spherical.

◆ __mul__() [1/2]

__mul__ (   self,
  factor 
)

Scale the vector uniformly up.

Parameters
factorThe scaling factor
Returns
The scaled vector
Remarks
This operation will scale the distance of the vector. The angle will be unaffected.

Reimplemented in Spherical, and Spherical.

◆ __truediv__() [1/2]

__truediv__ (   self,
  factor 
)

Scale the vector uniformly down.

Parameters
factorThe scaling factor
Returns
The scaled vector
Remarks
This operation will scale the distance of the vector. The angle will be unaffected.

Reimplemented in Spherical, and Spherical.

◆ Distance() [1/2]

float Distance (   v1,
  v2 
)
static

Calculate the distance between two spherical coordinates.

Parameters
v1The first coordinate
v2The second coordinate
Returns
The distance between the coordinates in meters

Reimplemented in Spherical, and Spherical.

◆ Angle() [1/2]

Angle Angle (   v1,
  v2 
)
static

Calculate the unsigned angle between two spherical vectors.

Parameters
v1The first vector
v2The second vector
Returns
The unsigned angle between the vectors [0..179.9999999..., -180]
Remarks
the strange range is caused by the 2s complement signed values which has range [minvalue..maxvalue). This is a hardware limitation, not something we can change.

Reimplemented in Spherical, and Spherical.

◆ SignedAngle() [1/2]

Angle SignedAngle (   v1,
  v2 
)
static

Calculate the unsigned angle between two spherical vectors.

Parameters
v1The first vector
v2The second vector
Returns
The unsigned angle between the vectors [0..179.9999999..., -180]
Remarks
the strange range is caused by the 2s complement signed values which has range [minvalue..maxvalue). This is a hardware limitation, not something we can change.

Reimplemented in Spherical, and Spherical.

◆ Lerp() [1/2]

Lerp (   v1,
  v2,
float  f 
)

Lerp (linear interpolation) between two vectors.

Parameters
v1The starting vector
v2The ending vector
fThe interpolation distance
Returns
The lerped vector
Remarks
The factor f is unclamped. Value 0 matches the vector v1, Value 1 matches vector v2. Value -1 is vector v1 minus the difference between v1 and v2 etc.

◆ Degrees() [2/2]

Degrees ( float  distance,
float  degrees 
)

Create a polar vector without using the Angle type.

All given angles are in degrees

Parameters
distanceThe distance in meters
horizontalThe angle in degrees
Returns
The polar vector

Reimplemented in Spherical, and Spherical.

◆ Radians() [2/2]

Radians ( float  distance,
float  radians 
)

Create polar vector without using the Angle type.

All given angles are in radians

Parameters
distanceThe distance in meters
horizontalThe horizontal angle in radians
verticalThe vertical angle in radians
Returns
The polar vector

Reimplemented in Spherical, and Spherical.

◆ FromVector2() [2/2]

FromVector2 ( Vector2  v)
static

Create a polar coordinate from a Vector2 coordinate.

Parameters
vThe vector coordinate
Returns
The polar coordinate

◆ ToVector2() [2/2]

Vector2 ToVector2 (   self)

Convert the polar coordinate to a Vector2 coordinate.

Returns
The vector coordinate

◆ __eq__() [2/2]

bool __eq__ (   self,
  other 
)

Check if this vector is equal to the given vector.

Parameters
vThe vector to check against
Returns
true if it is identical to the given vector
Note
This uses float comparison to check equality which may have strange effects. Equality on floats should be avoided.

Reimplemented in Spherical, and Spherical.

◆ __neg__() [2/2]

__neg__ (   self)

Negate the vector.

Returns
The negated vector This will negate the direction. Distance will stay the same.

Reimplemented in Spherical, and Spherical.

◆ __sub__() [2/2]

__sub__ (   self,
  other 
)

Subtract a polar vector from this vector.

Parameters
otherThe vector to subtract
Returns
The result of the subtraction

Reimplemented in Spherical, and Spherical.

◆ __add__() [2/2]

__add__ (   self,
  other 
)

Add a polar vector to this vector.

Parameters
otherThe vector to add
Returns
The result of the addition

Reimplemented in Spherical, and Spherical.

◆ __mul__() [2/2]

__mul__ (   self,
  factor 
)

Scale the vector uniformly up.

Parameters
factorThe scaling factor
Returns
The scaled vector
Remarks
This operation will scale the distance of the vector. The angle will be unaffected.

Reimplemented in Spherical, and Spherical.

◆ __truediv__() [2/2]

__truediv__ (   self,
  factor 
)

Scale the vector uniformly down.

Parameters
factorThe scaling factor
Returns
The scaled vector
Remarks
This operation will scale the distance of the vector. The angle will be unaffected.

Reimplemented in Spherical, and Spherical.

◆ Distance() [2/2]

float Distance (   v1,
  v2 
)
static

Calculate the distance between two spherical coordinates.

Parameters
v1The first coordinate
v2The second coordinate
Returns
The distance between the coordinates in meters

Reimplemented in Spherical, and Spherical.

◆ Angle() [2/2]

Angle Angle (   v1,
  v2 
)
static

Calculate the unsigned angle between two spherical vectors.

Parameters
v1The first vector
v2The second vector
Returns
The unsigned angle between the vectors [0..179.9999999..., -180]
Remarks
the strange range is caused by the 2s complement signed values which has range [minvalue..maxvalue). This is a hardware limitation, not something we can change.

Reimplemented in Spherical, and Spherical.

◆ SignedAngle() [2/2]

Angle SignedAngle (   v1,
  v2 
)
static

Calculate the unsigned angle between two spherical vectors.

Parameters
v1The first vector
v2The second vector
Returns
The unsigned angle between the vectors [0..179.9999999..., -180]
Remarks
the strange range is caused by the 2s complement signed values which has range [minvalue..maxvalue). This is a hardware limitation, not something we can change.

Reimplemented in Spherical, and Spherical.

◆ Lerp() [2/2]

Lerp (   v1,
  v2,
float  f 
)

Lerp (linear interpolation) between two vectors.

Parameters
v1The starting vector
v2The ending vector
fThe interpolation distance
Returns
The lerped vector
Remarks
The factor f is unclamped. Value 0 matches the vector v1, Value 1 matches vector v2. Value -1 is vector v1 minus the difference between v1 and v2 etc.

Member Data Documentation

◆ distance

distance

The direction of the vector.

Normalizing such that distance >= 0


The documentation for this class was generated from the following files: