Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Find the coordinates of the vertices of a cube with given central coordinates and length in python

I want to find the coordinates of the vertices of a cube with given central coordinates (Xc,Yc,Zc) and length (SL)

def vertices(Xc,Yc,Zc,SL):
    f1 = [(0.5*SL)+ Xc,Yc,Zc]  
    f2 = [(0.5*SL)- Xc,Yc,Zc]
  
    
    x1 = [f1[0],(f1[1])-(0.5*SL), (f1[2])+(0.5*SL)]
    x2 = [f1[0],(f1[1])+(0.5*SL), (f1[2])+(0.5*SL)]
    x3 = [f1[0],(f1[1])-(0.5*SL), (f1[2])-(0.5*SL)]
    x4 = [f1[0],(f1[1])+(0.5*SL), (f1[2])-(0.5*SL)]
    x5 = [f2[0],(f2[1])-(0.5*SL), (f2[2])+(0.5*SL)]
    x6 = [f2[0],(f2[1])+(0.5*SL), (f2[2])+(0.5*SL)]
    x7 = [f2[0],(f2[1])-(0.5*SL), (f2[2])-(0.5*SL)]
    x8 = [f2[0],(f2[1])+(0.5*SL), (f2[2])-(0.5*SL)]
    
    return x1,x2,x3,x4,x5,x6,x7,x8
x1,x2,x3,x4,x5,x6,x7,x8 = vertices(5,5,5,8)

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

It’s best if you return a list with 8 points (sublists) than 8 different variables.

From the caller perspective it will be the same, you can still unpack it as 8 different variables.

def vertices(Xc,Yc,Zc,SL):
    return [[Xc + SL/2, Yc + SL/2, Zc + SL/2],
            [Xc + SL/2, Yc + SL/2, Zc - SL/2],
            [Xc + SL/2, Yc - SL/2, Zc + SL/2],
            [Xc + SL/2, Yc - SL/2, Zc - SL/2],
            [Xc - SL/2, Yc + SL/2, Zc + SL/2],
            [Xc - SL/2, Yc + SL/2, Zc - SL/2],
            [Xc - SL/2, Yc - SL/2, Zc + SL/2],
            [Xc - SL/2, Yc - SL/2, Zc - SL/2]]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading