Announcements
Visit Fusion 360 Feedback Hub, the great way to connect to our Product, UX, and Research teams. See you there!
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Add operator overloading to Points and Vectors

Add operator overloading to Points and Vectors

Some basic operator overloading would make working with points and vectors way easier.

Here an example of adding a vector scaled by a factor of 3 to a point:

 

Now:

 

tempVector = originalVector.copy()
tempVector.scaleBy(3)
resultPoint = originalPoint.copy()
resultPoint.translateBy(tempVector)

With operator overloading:

 

 

resultPoint = originalPoint + originalVector * 3

 

Here would be my suggestion. It will use Points and Vectors interchangeably as they are very similar:

Vector1 + Vector2 = Vector3
behaves like:
Vector3 = Vector1.copy().add(Vector2) Vector1 * number = Vector2 behaves like:
Vector2 = Vector1.copy().scaleBy(number) Vector1 - Vector2 = Vector3 behaves like: Vector4 = Vector2.copy() Vector4.scaleBy(-1) Vector3 = Vector1.copy().add(Vector4) Vector1 / number = Vector2 behaves like:
Vector2 = Vector1.copy().scaleBy(1/number) Vector1 += Vector2 behaves like:
Vector1.add(Vector2) Vector1 *= number behaves like:
Vector1.scaleBy(number) Vector1 -= Vector2 behaves like: Vector3 = vector2.copy() Vector3.scaleBy(-1) Vector1.add(Vector3) Vector1 /= number behaves like:
Vector1.scaleBy(1/number)

I would assume the previous suggestions to be universally accepted. Here are some more that would be useful:

str(Vector) = "[x, y, z]"
behaves like:
def __str__(self):
    return "[{:g}, {:g}, {:g}]".format(self.x, self.y, self.z)

reason:
This makes debugging easier as it returns the actual components of the vector instead of just the Class. Class type can still be accessed.


abs(Vector) = length
behaves like:
def __abs__(self):
    return self.length


setter method for Vector.length
behaves like:
def _set_length(self, length):
    self.scaleBy(length / self._get_length())


Vector1 * Vector2 = dotProduct
behaves like:
dotProduct = Vector1.dotProduct(Vector2)

 

Can't find what you're looking for? Ask the community or share your knowledge.

Submit Idea  

Autodesk Design & Make Report