-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprojray2hyperplane.m
51 lines (40 loc) · 1.05 KB
/
projray2hyperplane.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
function a = projray2hyperplane(nvec,pt)
% PROJRAY2HYPERPLANE Project ray (pt) from unit hypersphere to tangent hyperplane at another point (nvec)
%--------------------------------------------------------------------------
% Author: Sterling Baird
%
% Date: 2020-07-03
%
% Inputs:
% nvec === normalized normal to hyperplane
%
% pt === point to project from hypersphere to hyperplane
%
% Intermediates:
%
% d === dimensionality
%
% dist === distance from origin to hyperplane (same as radius of
% hypersphere)
%
% t === parametric value that scales pt to the intersection of pt
% and tangent hyperplane.
%
% Outputs:
%
% a === intersection of pt and tangent hyperplane defined by nvec
%
% References:
% https://math.stackexchange.com/q/1256236/798661
%
% http://comprna.upf.edu/courses/Master_MAT/3_Optimization/U9_Hyperplanes.pdf
%--------------------------------------------------------------------------
%dimensionality
d = length(nvec);
%distance
dist = norm(nvec);
%parametric value
t = dist/dot(nvec,pt);
%intersection
a = -pt*(-t);
end