Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add matrix transpose multiplication #494

Open
bitshifter opened this issue Mar 14, 2024 Discussed in #358 · 0 comments
Open

Add matrix transpose multiplication #494

bitshifter opened this issue Mar 14, 2024 Discussed in #358 · 0 comments

Comments

@bitshifter
Copy link
Owner

Discussed in #358

Originally posted by dataphract October 31, 2022
In collision detection, it's often useful to perform computations in the local space of one of the involved objects.

For instance, given an OBB:

struct Obb {
    half_extents: Vec3,
    orientation: Vec3,
}

the closest point within the OBB to another point can be found like so:

impl Obb {
    fn closest(&self, other: Vec3) -> Vec3 {
        let inv_orientation = self.orientation.transpose();
        let local_other = inv_orientation * other;
        self.orientation * local_other.clamp(-self.half_extents, self.half_extents)
    }
}

other is converted to the local space of self by premultiplying by the inverse of self.orientation, and since self.orientation is an orthonormal basis, its inverse is equivalent to its transpose. However, it's not necessary to actually construct the transposed matrix -- the multiplication can be performed by dotting the columns of the left-hand side with the columns of the right.

Ideally, we could instead write:

impl Obb {
    fn closest(&self, other: Vec3) -> Vec3 {
        let local_other = self.orientation.mul_transpose(other); // or transpose_mul(), if you like
        self.orientation * local_other.clamp(-self.half_extents, self.half_extents)
    }
}
```</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant