source: CPL/oasis3-mct/branches/OASIS3-MCT_2.0_branch/util/oasisgui/XDRpy/data3d.py

Last change on this file was 4775, checked in by aclsce, 5 years ago
  • Imported oasis3-mct from Cerfacs svn server (not suppotred anymore).

The version has been extracted from https://oasis3mct.cerfacs.fr/svn/branches/OASIS3-MCT_2.0_branch/oasis3-mct@1818

File size: 2.1 KB
Line 
1#!/usr/bin/env python
2
3from itertools import izip
4from math import sqrt,atan2,pi,hypot,cos,sin
5
6def grouped(iterable, n):
7    "s -> (s0,s1,s2,...sn-1), (sn,sn+1,sn+2,...s2n-1), (s2n,s2n+1,s2n+2,...s3n-1), ..."
8    return izip(*[iter(iterable)]*n)
9
10def norm(u):
11    return sqrt(u["x"]**2+u["y"]**2+u["z"]**2)
12
13
14def rotate(y,z,rotate_deg):
15    r = hypot(z,y)
16    theta = atan2(z,y) + rotate_deg*pi/180
17    y = r*cos(theta)
18    z = r*sin(theta)
19    return [y,z] 
20   
21
22def makevect(points,a,b):
23    res = {}
24    res["x"] = points[b,"x"] - points[a,"x"]
25    res["y"] = points[b,"y"] - points[a,"y"]
26    res["z"] = points[b,"z"] - points[a,"z"]
27    return res
28
29   
30def pvect(u,v):
31    res = {}
32    res["x"] = u["y"]*v["z"]- u["z"]*v["y"]
33    res["y"] = u["z"]*v["x"]- u["x"]*v["z"]
34    res["z"] = u["x"]*v["y"]- u["y"]*v["x"]
35    return res
36
37
38def getparts(data,subpart=""):
39    if subpart != "" :
40        subpart = "."+subpart
41    res = None
42    i = data.index("root"+subpart+".children :")
43    i+=1
44    res = data[i].strip().split(",")   
45    return res
46   
47def dumpparts(list_parts,subpart=""):
48    if subpart != "" :
49        subpart = "."+subpart
50    res = "root"+subpart+".children :\n"+ ",".join(list_parts)+"\n\n"
51    return res
52
53def getfield(part,field,data,datatype="integer",subpart=""):
54    if subpart != "" :
55        subpart = "."+subpart
56   
57    i = data.index("root."+part+subpart+"."+field+" :")
58    i +=1
59    j = i
60    while data[j] != "" :
61        j += 1
62    out = filter(None,",".join(data[i:j]).split(","))
63   
64   
65    if field == "children" :
66        datatype = "spacedstring"
67   
68   
69    if datatype == "spacedstring":
70        pass
71    if datatype == "float":
72        out  =[float(x) for x in out]
73    if datatype == "integer":
74        out  =[int(x) for x in out]       
75    return out
76   
77def dumpfield(part,field,listdata,subpart="") :
78    if subpart != "" :
79        subpart = "."+subpart
80       
81    dump = "root."+part+subpart+"."+field+" :\n"
82    maxcol = 10
83    col = 1
84    for item in listdata:
85        dump += str(item) +","
86        if col == maxcol :
87            dump += "\n"
88            col = 1
89        col += 1
90   
91    dump += "\n\n"
92    return dump
Note: See TracBrowser for help on using the repository browser.