# Message #4207

From: programagor@gmail.com

Subject: Spherical distortion on 4D to 3D cameras

Date: Mon, 05 Aug 2019 01:22:45 -0700

Greetings

I was playing with Python in Blender, and created a function that maps a 4D point p to a 3D point r using a camera at 4D point c looking in a direction defined by a 4D vector v. This uses perspective projection, like you’d do in 3D -> 2D, but I was interested in a "Fisheye Lens" effect.

To do this, I implemented the Cube to Sphere formula found here, then applied it on every point of the original 3D object.

Anyway, the result is this:

And here is the code to do the 4D -> Fisheye 3D:

import numpy as np

def map4to3(c: np.array,v: np.array,p: np.array) -> np.array:

# Move camera to center

p_moved=p-c

# Normalise camera vector

# just in case, assume it’s normal, or at least non-zero

v_normed=v/np.linalg.norm(v)

#Rotate world so that camera points in direction [1,0,0,0]

#TODO

#one axis at a time

#bring (a1,b1,c1,d1) to (a2,b2,c2,0)

#bring (a2,b2,c2,0) to (a3,b3,0,0)

#bring (a3,b3,0,0) to (a4,0,0,0)

#Rotate the world more so that camera is level

#rotate along (1,0,0,0)

r=np.array([])

for a in range(0,p.size-1):

r=np.append(r,atan2(p_moved[a+1],p_moved[0]))

#return r

return map_cube_to_sphere(r)

def map_cube_to_sphere(p: np.array) -> np.array:

r=np.array([

p[0]*sqrt(1-p[1]**2/2-p[2]**2/2+p[1]**2*p[2]**2/3),

p[1]*sqrt(1-p[2]**2/2-p[0]**2/2+p[2]**2*p[0]**2/3),

p[2]*sqrt(1-p[0]**2/2-p[1]**2/2+p[0]**2*p[1]**2/3)

])

return r