-
Notifications
You must be signed in to change notification settings - Fork 2
/
get_H.m
83 lines (75 loc) · 2.16 KB
/
get_H.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
function [Hx, Hy, Hz, gx, gy, gz] = get_H(Face, cor, Un, M, density)
% get_H computes the magnetic and gravity anomaly
%
% get_H computes the magnetic and gravity anomaly at the origin of a
% right-handed coordinate system. The anomalies are caused by a solid body
% of homogeneous magnetization and/or density.
% The shape of the body is approximated by a sufficiently large number of
% vertices. The convex (or concave) hull is provided by a Delaunay
% triangulation.
%
% [Bx, By, Bz, gx, gy, gz] = get_H(face, vtx, un, m, density)
%
% Input:
% =====
%
% faces: (nf x 3) array of indices into the array of triangles vtx
% vtx: (nc x 3) array of triangular vertex coordinates
% un: (nf x 3) array of unit vectors normal to the triangular faces
% m: (3 x 1) array of induced magnetization of the body enclosed by triangulation, given in A/m
% density: mass density of the body, given in kg/m^3
%
% Output:
% ======
%
% Bx, By, Bz: Cartesian components of the magnetic anomaly B at the origin of
% a right-handed coordinate system, given in nanoTesla (nT)
% gx, gy, gz: Cartesian components of the gravitational attraction g at the
% origin of a right-handed coordinate system, given in SI units of m/s^2
%
%
arguments
Face (:, 3)
cor (:, 3)
Un (:, 3)
M (3,1) {mustBeNumeric}
density double {mustBeNumeric}
end
[Hx, Hy, Hz] = deal(0.0, 0.0, 0.0);
[gx, gy, gz] = deal(0.0, 0.0, 0.0);
rhof = density * 6.6732e-11;
Nf = size(Face, 1);
cor = cor';
M = 1e-7 * M;
for f = 1:Nf
idx = Face(f, :);
crs = cor(:, idx);
A = crs(:, 1);
B = crs(:, 2);
C = crs(:, 3);
N = Un(f, :);
Omega = TriAngle(C, B, A);
di = dot(A, N);
if di < 0
Omega = -sign(di) * Omega;
end
PQR = get_PQR(crs);
l = N(1);
m = N(2);
n = N(3);
p = PQR(1);
q = PQR(2);
r = PQR(3);
hx = l * Omega + n * q - m * r;
hy = m * Omega + l * r - n * p;
hz = n * Omega + m * p - l * q;
Pd = N * M;
Hx = Hx + Pd * hx;
Hy = Hy + Pd * hy;
Hz = Hz + Pd * hz;
di = rhof * di;
gx = gx - di * hx;
gy = gy - di * hy;
gz = gz - di * hz;
end
end