简体   繁体   中英

How do I define a hyperplane in Python given 4 points? How do I then define the intersection of 4 hyperplanes (this should be a point)?

I have 4 points in R4 and their co-ordinates:

P1:[x1, y1, z1, w1] 
P2:[x2, y2, z2, w2]
P3:[x3, y3, z3, w3]
P4:[x4, y4, z4, w4]

How do I now define a hyperplane out of these points in Python?

Also given that I have the equations of 4 hyperplanes how do I get their intersection (which should be a point)?

Thanks! O.

Equation of an hyperplane.

An hyper plane in Rn can be described, given a non zero constant K and a set of coefficients a ={a_1 ... a_n}, as the set of points x =(x_1 .. x_n) that solve the equation

Sum(a_n * x_n) = k

choosing k=1 in R4, and with

X= ( P1;P2;P3;P4)

You can solve your coefficients a by doing

X a = 1

a = X^-1 * 1


Part 2 is more of of the same.

Having 4 sets of equations

x a = k

the point that belongs to them all can be solved as

x = k ' A^-1


On numpy that's:

import numpy as np
def hyper4(p1,p2,p3,p4):
   X=np.matrix([p1,p2,p3,p4])
   k=np.ones((4,1))
   a=numpy.matrix.dot(np.linalg.inv(X), k)
   print "equation is x * %s = 1" % a
   return a

Usage:

   hyper4([0,0,1,1],[0,3,3,0],[0,5,2,0],[1,0,0,7])

And for the point

a1=hyper4(P1,P2,P3,P4)
a2=hyper4(P5,P6,P7,P8)
a3=hyper4(P9,P10,P11,P12)
a4=hyper4(P13,P14,P15,P16)

A=np.hstack([a1,a2,a3,a4])
k=np.ones((1,4))

x=numpy.matrix.dot(k, np.linalg.inv(A))
print "your point is %s" % x

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM