# Custom array for 3D-Matrix operations 4x4

**URL:** <https://discourse.julialang.org/t/custom-array-for-3d-matrix-operations-4x4/16568>\
**Category:** General Usage\
**Created:** [October 20, 2018, 2:30pm UTC](https://discourse.julialang.org/t/custom-array-for-3d-matrix-operations-4x4/16568 "2018-10-20T14:30:49Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ralf\_Dietrich](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ralf_dietrich/32/5643_2.png) [@Ralf\_Dietrich](https://discourse.julialang.org/u/Ralf_Dietrich)\
**Post date:** [October 20, 2018, 2:30pm UTC](https://discourse.julialang.org/t/custom-array-for-3d-matrix-operations-4x4/16568/1 "2018-10-20T14:30:49Z")

</div>

I need a structure like that, as a custom array 4x4 for 3D-calculations:

Matrix3D = zeros(Float64, 4, 4)

I tried to define it like that, but i stuck:

struct Matrix3D \<: Abstract???  
???  
end

to use it:

myMatrix3D = Matrix3D ???

assigning values like that:

myMatrix3D[1, 4] = 3.0

or working like that:  
myMatrix3D[2, 2] = cos(w); myMatrix3D[2, 3] = -sin(w)  
myMatrix3D[3, 2] = sin(w); myMatrix3D[3, 3] = cos(w)

any help for me?

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [October 20, 2018, 2:37pm UTC](https://discourse.julialang.org/t/custom-array-for-3d-matrix-operations-4x4/16568/2 "2018-10-20T14:37:06Z")

</div>

Check out StaticArrays.jl for fixed size arrays and maybe Rotations.jl for rotation matrices.  
[https://github.com/FugroRoames/Rotations.jl/blob/master/README.md](https://github.com/FugroRoames/Rotations.jl/blob/master/README.md)

---

<div class="post-metadata">

**Author:** ![tkoolen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkoolen/32/1603_2.png) [@tkoolen](https://discourse.julialang.org/u/tkoolen)\
**Post date:** [October 20, 2018, 3:07pm UTC](https://discourse.julialang.org/t/custom-array-for-3d-matrix-operations-4x4/16568/3 "2018-10-20T15:07:43Z")

</div>

Will you be using this type as a homogeneous transform (rotation + translation)?

---

<div class="post-metadata">

**Author:** ![Ralf\_Dietrich](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ralf_dietrich/32/5643_2.png) [@Ralf\_Dietrich](https://discourse.julialang.org/u/Ralf_Dietrich)\
**Post date:** [October 20, 2018, 3:08pm UTC](https://discourse.julialang.org/t/custom-array-for-3d-matrix-operations-4x4/16568/4 "2018-10-20T15:08:27Z")

</div>

yes, I do

---

<div class="post-metadata">

**Author:** ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)\
**Post date:** [October 20, 2018, 3:37pm UTC](https://discourse.julialang.org/t/custom-array-for-3d-matrix-operations-4x4/16568/5 "2018-10-20T15:37:46Z")

</div>

> > Will you be using this type as a homogeneous transform (rotation + translation)?

> yes, I do

Then try [GitHub - JuliaGeometry/CoordinateTransformations.jl: A fresh approach to coordinate transformations...](https://github.com/FugroRoames/CoordinateTransformations.jl)

---

<div class="post-metadata">

**Author:** ![Ralf\_Dietrich](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ralf_dietrich/32/5643_2.png) [@Ralf\_Dietrich](https://discourse.julialang.org/u/Ralf_Dietrich)\
**Post date:** [October 20, 2018, 3:40pm UTC](https://discourse.julialang.org/t/custom-array-for-3d-matrix-operations-4x4/16568/6 "2018-10-20T15:40:33Z")

</div>

> [@tim.holy](#):
>
> Then try [GitHub - JuliaGeometry/CoordinateTransformations.jl: A fresh approach to coordinate transformations...](https://github.com/FugroRoames/CoordinateTransformations.jl)

TY. It’s already known. For me its important to do I by my self (for learling purposes)

---

<div class="post-metadata">

**Author:** ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)\
**Post date:** [October 20, 2018, 3:45pm UTC](https://discourse.julialang.org/t/custom-array-for-3d-matrix-operations-4x4/16568/7 "2018-10-20T15:45:26Z")

</div>

I would start by learning the [AbstractArray interface](https://docs.julialang.org/en/v1.0/manual/interfaces/#man-interface-array-1). Also make sure you’re up on [Parametric types](https://docs.julialang.org/en/v1.0/manual/types/#Parametric-Types-1) since you’ll probably want to encode array size as a parameter. Then try writing a simple custom type from scratch. You can find many examples of simple AbstractArray types at [JuliaArrays](https://github.com/JuliaArrays).

StaticArrays does what you want and would be a good example, but if you haven’t already written a custom AbstractArray type it might be challenging learning: StaticArrays is very sophisticated and has to jump through hoops to handle immutability.

---

<div class="post-metadata">

**Author:** ![Ralf\_Dietrich](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ralf_dietrich/32/5643_2.png) [@Ralf\_Dietrich](https://discourse.julialang.org/u/Ralf_Dietrich)\
**Post date:** [October 20, 2018, 3:48pm UTC](https://discourse.julialang.org/t/custom-array-for-3d-matrix-operations-4x4/16568/8 "2018-10-20T15:48:51Z")

</div>

I already tried that but i stucked.

A small working example for me would be very helpful

---

<div class="post-metadata">

**Author:** ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)\
**Post date:** [October 20, 2018, 3:50pm UTC](https://discourse.julialang.org/t/custom-array-for-3d-matrix-operations-4x4/16568/9 "2018-10-20T15:50:09Z")

</div>

Take a look at [MappedArrays](https://github.com/JuliaArrays/MappedArrays.jl) and [IndirectArrays](https://github.com/JuliaArrays/IndirectArrays.jl); they’re both relatively simple.
