 # QMatrix4x4 operator* with QVector3D is unclear

XMLWordPrintable

#### Details

• Type: Suggestion
• Status: Reported
• Priority: P3: Somewhat important
• Resolution: Unresolved
• Affects Version/s: 5.15.2, 6.0.0
• Fix Version/s: None
• Component/s:
• Labels:
None

#### Description

QVector3D documentation says `"The QVector3D class represents a vector or vertex in 3D space." `

QMatrix4x4 provides an operator* to transform a QVector3D. This has several issues:

1. Using * remembers of an algebraic operation, which is incorrect between a 4x4 matrix and a 3x1 vector. This is implement as if the QVeector3D was a QVector4D with a 1 in the w coordinate and doing the mathematical operation.
2. By doing that, it fails the purpose of QVector3D being a vector or a vertex, since its always considered a vertex. You can't consider a vector because when transforming it with a QMatrix4x4 its going to be treated as a vertex.
3. Thee operator* remembers of the algebraic operation, so one could think that the distributive property applies, but it doesnt.

Consider the following code:

```QMatrix4x4 worldMatrix;
QVector3D p;
worldMatrix * p - worldMatrix * QVector3D(0,0,0);
```

p here is a vector, so when applying the worldMatrix transformation, I dont wan't the traslation. That is why I need to remove it with the `worldMatrix * QVector3D(0,0,0)`.

One could also consider that the code could be refactored as:

```QMatrix4x4 worldMatrix;
QVector3D p;
worldMatrix * p; // in algebra, multiplying by a null vector returns a null vector
```

which doesn't give the same result.

I would suggest deprecating and removing all the non mathematical operations and use proper algebra for these operations.

#### People

Assignee: Laszlo Agocs
Reporter: Juan José Casafranca