# Find angle made by Dipole

**URL:** <https://mne.discourse.group/t/find-angle-made-by-dipole/4983>\
**Category:** Support & Discussions\
**Tags:** dipole-fit\
**Created:** [June 1, 2022, 7:22pm UTC](https://mne.discourse.group/t/find-angle-made-by-dipole/4983 "2022-06-01T19:22:50Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rekha](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/rekha/32/1372_2.png) [@Rekha](https://mne.discourse.group/u/Rekha)\
**Post date:** [June 1, 2022, 7:22pm UTC](https://mne.discourse.group/t/find-angle-made-by-dipole/4983/1 "2022-06-01T19:22:50Z")

</div>

Hi MNE users.

Can anybody tell me where the information regarding dipole orientation is stored when using dipole fitting function on MNE? I need to find the angle that dipole makes with lets say horizontal axis. How can I measure that?

 ![image](https://global.discourse-cdn.com/free1/uploads/mne/original/2X/9/94b08c6d81297ff16d0a5f664b401706865879b2.png)

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [June 1, 2022, 9:54pm UTC](https://mne.discourse.group/t/find-angle-made-by-dipole/4983/2 "2022-06-01T21:54:40Z")

</div>

Hello @Rekha,

if you have a dipole object `dip`, you can get the “orientation vectors” for all time points via:

```python
dip.ori

```

In this array, each row is a “unit vector” (length 1) with 3 coordinates (x, y, z). Proof that they all have unit length:

```python
# %%
# Create dipole fits
import os.path as op
import numpy as np
import mne

data_path = mne.datasets.sample.data_path()
subjects_dir = op.join(data_path, 'subjects')
fname_ave = op.join(data_path, 'MEG', 'sample', 'sample_audvis-ave.fif')
fname_cov = op.join(data_path, 'MEG', 'sample', 'sample_audvis-cov.fif')
fname_bem = op.join(subjects_dir, 'sample', 'bem', 'sample-5120-bem-sol.fif')
fname_trans = op.join(data_path, 'MEG', 'sample',
                      'sample_audvis_raw-trans.fif')

evoked = mne.read_evokeds(fname_ave, condition='Right Auditory',
                          baseline=(None, 0))
evoked.pick_types(meg=True)
evoked.crop(0.07, 0.08)

dip, _ = mne.fit_dipole(
    evoked, fname_cov, fname_bem, fname_trans, n_jobs=8
)

# calculate lengths of all "ori" vectors
print(np.linalg.norm(dip.ori, axis=1))

```

Returns:

```python
array([1., 1., 1., 1., 1., 1., 1.])

```

i.e., the `ori` vector of each of the 7 dipoles fitted in this example has a length of 1.

Knowing that we’re dealing with unit vectors in 3D space, you can use trigonometric functions to retrieve the angles you’re interested in. For example, this website explains how to do it, but it’s also something you can find in basically any maths book on analytic geometry:

> **[7. Vectors in 3-D Space](https://www.intmath.com/vectors/7-vectors-in-3d-space.php#directioncosines)**
>
> We extend vector concepts to 3-dimensional space. This section includes adding 3-D vectors, and finding dot and cross products of 3-D vectors.

Best wishes,  
Richard

---

<div class="post-metadata">

**Author:** ![Rekha](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/rekha/32/1372_2.png) [@Rekha](https://mne.discourse.group/u/Rekha)\
**Post date:** [June 1, 2022, 10:22pm UTC](https://mne.discourse.group/t/find-angle-made-by-dipole/4983/3 "2022-06-01T22:22:57Z")

</div>

Hi @richard, thank you for your reply.

Are these values in the Array equivalent to cosine alpha, cosine beta, cosine gamma of the directional cosines? or what exactly are they?

![image](https://global.discourse-cdn.com/free1/uploads/mne/original/2X/2/2b0be2c528af51668c6d5e146fd7cc75539845ee.png)

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [June 2, 2022, 12:17am UTC](https://mne.discourse.group/t/find-angle-made-by-dipole/4983/7 "2022-06-02T00:17:26Z")

</div>

(I removed my previous answers as I figured I need to get some sleep before thinking about math :))

---

<div class="post-metadata">

**Author:** ![bagginstyrone](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/bagginstyrone/32/375_2.png) [@bagginstyrone](https://mne.discourse.group/u/bagginstyrone)\
**Post date:** [June 2, 2022, 7:22am UTC](https://mne.discourse.group/t/find-angle-made-by-dipole/4983/8 "2022-06-02T07:22:50Z")

</div>

> [@Rekha](#):
>
> Are these values in the Array equivalent to cosine alpha, cosine beta, cosine gamma of the directional cosines? or what exactly are they?

No these values are not equivalent.

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [June 2, 2022, 9:10am UTC](https://mne.discourse.group/t/find-angle-made-by-dipole/4983/9 "2022-06-02T09:10:52Z")

</div>

Hello @Rekha, I will look into this again later today and try to provide an answer after I’ve freshened up my trigonometry knowledge 😃

---

<div class="post-metadata">

**Author:** ![agramfort](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@agramfort](https://mne.discourse.group/u/agramfort)\
**Post date:** [June 2, 2022, 11:59am UTC](https://mne.discourse.group/t/find-angle-made-by-dipole/4983/10 "2022-06-02T11:59:01Z")

</div>

> [@richard](#):
>
> `dip.ori`

is the moment in cartesian coordinates. You ask to get it in polar coordinate.

mne has a private function called \_cart\_to\_sph for this.

> <https://github.com/mne-tools/mne-python/blob/main/mne/transforms.py#L711>

Alex

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [June 2, 2022, 3:34pm UTC](https://mne.discourse.group/t/find-angle-made-by-dipole/4983/11 "2022-06-02T15:34:55Z")

</div>

@Rekha

I thought a bit about this and the approach I’d take is consider the 3 2D-planes xy, xz, yz separately and then use 2D trigonometry to solve the problem (calculating the one relevant angle of the right-angled triangle formed by vector and plane). `ori` then provides the lengths of the legs of the triangle.

But like @agramfort said, it’s not really clear **why** you’d even want to perform these calculations, as it’s usually a spherical coordinate system one would use to describe the angle(s) in 3D space.

Best wishes,  
Richard

---

<div class="post-metadata">

**Author:** ![Rekha](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/rekha/32/1372_2.png) [@Rekha](https://mne.discourse.group/u/Rekha)\
**Post date:** [June 2, 2022, 5:13pm UTC](https://mne.discourse.group/t/find-angle-made-by-dipole/4983/12 "2022-06-02T17:13:56Z")

</div>

Haha, Thank you so much for the effort Richard, I really appreciate it.
