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 primitives #40

Merged
merged 59 commits into from
Sep 6, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
d8f6a83
initial commit for matrix class
Revathyvenugopal162 Sep 1, 2022
d3287bc
Add inverse matrix
Revathyvenugopal162 Sep 1, 2022
665fe62
Add translation rotation
Revathyvenugopal162 Sep 1, 2022
e983d06
Add translation rotation
Revathyvenugopal162 Sep 1, 2022
f9fd6d8
Add translation matrix
Revathyvenugopal162 Sep 2, 2022
f7619e4
Merge branch 'main' into feat/add-matrix-primitives
Revathyvenugopal162 Sep 2, 2022
15dcaed
Add units radian as base unit
Revathyvenugopal162 Sep 2, 2022
bc5e458
Add rotation axis
Revathyvenugopal162 Sep 2, 2022
21e0867
Apply suggestions from code review
Revathyvenugopal162 Sep 2, 2022
5d3a541
Add docstrings for matrix33
Revathyvenugopal162 Sep 2, 2022
9624d40
Add docstrings for inverse
Revathyvenugopal162 Sep 2, 2022
b8335ed
Modify inverse
Revathyvenugopal162 Sep 2, 2022
e27fbfc
Add docstrings for rotations
Revathyvenugopal162 Sep 2, 2022
56eb473
Add docstrings for translate
Revathyvenugopal162 Sep 2, 2022
ad372fc
Update src/ansys/geometry/core/primitives/matrix.py
RobPasMue Sep 3, 2022
8154f83
Merge branch 'main' into feat/add-matrix-primitives
RobPasMue Sep 3, 2022
68f5ed0
Merge branch 'main' into feat/add-matrix-primitives
Revathyvenugopal162 Sep 5, 2022
d899f22
Apply suggestions from code review
Revathyvenugopal162 Sep 5, 2022
050f5de
Merge branch 'feat/add-matrix-primitives' of https://github.com/pyans…
Revathyvenugopal162 Sep 5, 2022
4915d2f
Modify rotation matrix
Revathyvenugopal162 Sep 5, 2022
bc9c509
Add determinent function
Revathyvenugopal162 Sep 5, 2022
7d5d5ad
Modify the imports and units
Revathyvenugopal162 Sep 5, 2022
3addc44
Modify rotation matrix for 4x4 matrix
Revathyvenugopal162 Sep 5, 2022
a8e982e
Initialise test for matrix
Revathyvenugopal162 Sep 5, 2022
3525d57
Add equa not equal operator
Revathyvenugopal162 Sep 5, 2022
b6990e0
Add matrix33 errors
Revathyvenugopal162 Sep 5, 2022
833dd6e
Merge branch 'main' into feat/add-matrix-primitives
Revathyvenugopal162 Sep 5, 2022
4348cb3
Add matrix 33 translate
Revathyvenugopal162 Sep 5, 2022
8cdf6ba
Merge branch 'main' into feat/add-matrix-primitives
Revathyvenugopal162 Sep 5, 2022
a2793c2
Add matrix 4x4 test
Revathyvenugopal162 Sep 5, 2022
64de143
Merge branch 'feat/add-matrix-primitives' of https://github.com/pyans…
Revathyvenugopal162 Sep 5, 2022
7cc7440
Add matrix 4x4 error test
Revathyvenugopal162 Sep 5, 2022
632d67c
Add matrix 4x4 rotation
Revathyvenugopal162 Sep 5, 2022
bbda00d
Merge branch 'main' into feat/add-matrix-primitives
Revathyvenugopal162 Sep 5, 2022
e610a98
Add np.pi for testing matrix
Revathyvenugopal162 Sep 5, 2022
35d29d8
Merge branch 'feat/add-matrix-primitives' of https://github.com/pyans…
Revathyvenugopal162 Sep 5, 2022
f874ab8
Add check function
Revathyvenugopal162 Sep 6, 2022
e9ef340
Add docstrings for the module
Revathyvenugopal162 Sep 6, 2022
6093cdb
Modify translation
Revathyvenugopal162 Sep 6, 2022
04d6d3b
Refactoring matrix
Revathyvenugopal162 Sep 6, 2022
6a5da63
Refactoring matrix tests
Revathyvenugopal162 Sep 6, 2022
8534c53
Refactoring matrix tests
Revathyvenugopal162 Sep 6, 2022
f01d14e
Apply suggestions from code review
Revathyvenugopal162 Sep 6, 2022
e82bd8d
Refactoring matrix tests for Matrix
Revathyvenugopal162 Sep 6, 2022
b158df3
Apply suggestions by @RobPasMue
Revathyvenugopal162 Sep 6, 2022
0ddb177
Modify Matrix44 class
Revathyvenugopal162 Sep 6, 2022
60a4c33
Merge branch 'main' into feat/add-matrix-primitives
Revathyvenugopal162 Sep 6, 2022
035cd36
Apply suggestions from code review
Revathyvenugopal162 Sep 6, 2022
d83fd63
Apply suggestions from code review
Revathyvenugopal162 Sep 6, 2022
b8a3f02
General typos and making Matrix objects immutable
RobPasMue Sep 6, 2022
d0ea64f
Modify Matrix multiplication
Revathyvenugopal162 Sep 6, 2022
9b4fd16
Merge branch 'feat/add-matrix-primitives' of https://github.com/pyans…
Revathyvenugopal162 Sep 6, 2022
56521a8
Modify Matrix multiplication test
Revathyvenugopal162 Sep 6, 2022
47b0b3b
Merge branch 'main' into feat/add-matrix-primitives
Revathyvenugopal162 Sep 6, 2022
e2de186
Refactor modules and test with updation
Revathyvenugopal162 Sep 6, 2022
1333c6b
Merge branch 'main' into feat/add-matrix-primitives
MaxJPRey Sep 6, 2022
f4bebf5
Apply suggestions from code review by @RobPasMue
RobPasMue Sep 6, 2022
3ff1a2d
Update src/ansys/geometry/core/math/matrix.py
RobPasMue Sep 6, 2022
9247b13
Update tests/test_math.py
RobPasMue Sep 6, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/ansys/geometry/core/primitives/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
"""PyGeometry primitives subpackage."""
from ansys.geometry.core.primitives.matrix import Matrix33, Matrix44, RotationMatrix
from ansys.geometry.core.primitives.point import Point2D, Point3D
from ansys.geometry.core.primitives.vector import UnitVector2D, UnitVector3D, Vector2D, Vector3D

__all__ = ["Point2D", "Point3D", "UnitVector2D", "UnitVector3D", "Vector2D", "Vector3D"]
__all__ = [
"Point2D",
"Point3D",
"UnitVector2D",
"UnitVector3D",
"Vector2D",
"Vector3D",
"Matrix33",
"Matrix44",
"RotationMatrix",
]
78 changes: 78 additions & 0 deletions src/ansys/geometry/core/primitives/matrix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
from math import cos, sin

import numpy as np

from ansys.geometry.core.primitives.vector import Vector2D, Vector3D


class Matrix33(np.ndarray):
def __new__(cls, input):
"""Constructor for ``Point3D``."""
RobPasMue marked this conversation as resolved.
Show resolved Hide resolved

matrix = np.asarray(input).view(cls)

if matrix is None or matrix.ndim != 2 or matrix.shape != (3, 3):
raise ValueError("Matrix33 should only be a 2D array of shape (3,3).")

if not np.issubdtype(matrix.dtype, np.number) or not isinstance(matrix, (np.ndarray)):
raise ValueError("The input parameters should be integer or float.")
RobPasMue marked this conversation as resolved.
Show resolved Hide resolved

return matrix

def inverse(self):
det = np.linalg.det(self)
Revathyvenugopal162 marked this conversation as resolved.
Show resolved Hide resolved
if det == 0:
raise ValueError("The determinent of matrix is zero, cannot be inversed")
Revathyvenugopal162 marked this conversation as resolved.
Show resolved Hide resolved
return np.linalg.inv(self)
RobPasMue marked this conversation as resolved.
Show resolved Hide resolved


class Matrix44(np.ndarray):
def __new__(cls, input):
"""Constructor for ``Point3D``."""
Revathyvenugopal162 marked this conversation as resolved.
Show resolved Hide resolved

matrix = np.asarray(input).view(cls)

if matrix is None or matrix.ndim != 2 or matrix.shape != (4, 4):
raise ValueError("Matrix44 shouldonly be a 2D array of shape (4,4).")
Revathyvenugopal162 marked this conversation as resolved.
Show resolved Hide resolved

if not np.issubdtype(matrix.dtype, np.number) or not isinstance(matrix, (np.ndarray)):
raise ValueError("The input parameters should be integer or float.")

return matrix

def inverse(self):
det = np.linalg.det(self)
if det == 0:
raise ValueError("The determinent of matrix is zero, cannot be inversed")
Revathyvenugopal162 marked this conversation as resolved.
Show resolved Hide resolved
return np.linalg.inv(self)


# from ansys.geometry.core.primitives import Matrix33
# a = Matrix33([[1,2,3],[2,5,6],[2,5,10]])
# b = Matrix33([[1,0,0],[0,1,0],[0,0,1]])
class RotationMatrix(Matrix33):
Revathyvenugopal162 marked this conversation as resolved.
Show resolved Hide resolved
def __new__(cls, input, theta):
obj = Matrix33(input)
rot = np.array([[cos(theta), -sin(theta), 0], [sin(theta), cos(theta), 0], [0, 0, 1]])
return np.multiply(rot, obj)
Revathyvenugopal162 marked this conversation as resolved.
Show resolved Hide resolved


class TranslationMatrix(Matrix33):
def __new__(cls, input, v: Vector2D):
Revathyvenugopal162 marked this conversation as resolved.
Show resolved Hide resolved
obj = Matrix33(input)
translate = np.array([[0, 0, v.x], [0, 0, v.y], [0, 0, 1]])
return np.multiply(obj, translate)

Revathyvenugopal162 marked this conversation as resolved.
Show resolved Hide resolved

class TranslateRotateMatrix(Matrix44):
def __new__(cls, input, angle, v: Vector3D):
obj = Matrix44(input)
transrot = np.array(
[
[0, 0, 0, v.x],
[0, cos(angle), -sin(angle), v.y],
[0, sin(angle), cos(angle), v.z],
[0, 0, 0, 1],
]
)
return np.multiply(obj, transrot)
Revathyvenugopal162 marked this conversation as resolved.
Show resolved Hide resolved