Mit der 4x4-Transformationsmatrix einer Kugel und einem Punkt im Raum möchte ich den nächsten Punkt auf der Kugeloberfläche finden.Abfrage des nächsten Punkts einer transformierten Kugel
Normalerweise würde ich eine Linie zwischen dem Punkt und der Kugelmitte ziehen und den Radius der Kugel verwenden, um meine Lösung zu erhalten, aber hier habe ich es mit einer nicht gleichmäßig skalierten Kugel zu tun. Hier ist ein kurzes Beispiel in Python:
import numpy as np
from numpy.core.umath_tests import inner1d
# 4x4 transform matrix of a sphere with the following components:
# Scale XYZ = 1,5,1 (Scaled only in Y axis to keep this example simple)
# Rotation XYZ = 0,0,45 (Simple tilt for this example)
# Position XYZ = -1,3,0 (Position along XY plane, again for simplicity)
M = np.array([[ 0.70710678, 0.70710678, 0. , 0. ],
[-3.53553391, 3.53553391, 0. , 0. ],
[ 0. , 0. , 1. , 0. ],
[-1. , 3. , 0. , 1. ]])
# Query point p0
p0 = np.array([-2,6,0])
# Transform the point into a unit sphere
I = np.linalg.inv(M)
p1 = np.array(p)-M[3,:3]
p1 = np.dot(p1,I)
# Normalize the point so it is on the surface of the unit sphere
mag = np.sqrt(inner1d(p1,p1)) # magnitude
p1 /= mag
# Transform back into 3D space
p1 = np.dot(p1,M[:3,:3]) + M[3,:3] #result [-1.65653216, 4.96959649, 0.]
Diese Lösung ist schnell und funktioniert gut, wenn die Abfrage Punkt auf den Bereich bereits in der Nähe ist, aber nicht so viel, wenn es entfernt ist. Siehe im Bild oben: Punkt p2, was das gewünschte Ergebnis wäre.
sehen Sie meine Suche nach [Ray und Ellipsoid Kreuzungsgenauigkeit Verbesserung] (http://stackoverflow.com/q/25470493/2521214) – Spektre