what is the specific function of parameter value in bpy.ops.transform.rotate phyton script in blender? - blender

i'm trying to make the object parallel to the z - axis by using bpy.ops.transform.rotate(value=90.0, axis=(1,0,0)) but all i got is this
enter image description here
import bpy
ungu = bpy.data.materials.new('Ungu')
ungu.diffuse_color=(0.6,0.1,0.3)
for i in range (5) :
x = i*2
y = 0
z = 0
bpy.ops.mesh.primitive_plane_add(location=(x,y,z))
ob=bpy.context.object
ob.name='PLANE'
mymesh=ob.data
ob.scale=((0.5,3,2))
#aplikasikan warna ungu ke objek mesh
mymesh.materials.append(ungu)
bpy.ops.transform.rotate(value=90.0, axis=(1,0,0))
so what number should i put in value parameter?

the value argument should be in radians but you are using degrees. I am not sure which version of Blender you are using, but acording to docs for Blender 2.82a https://docs.blender.org/api/current/bpy.ops.transform.html the transform function should be called like this:
bpy.ops.transform.rotate(value=3.14/2, orient_axis='X')

Related

Triangulated vtp File Plot Problem - matplotlib OpenFOAM vs Paraview Cut

maybe you can help me out with a right comment or hint for my problem.
Pretty easy, I would like to plot a 2D slice vtp file (OpenFOAM) via matplotlib as tricontourf plot.
1.) Creating the vtp slice by Paraview and saving as vtp file works like a charme
2.) Using the runtime vtp file, created by cuttingPlane - libsampling OpenFOAM creates a weird triangle order.
What am I missing?
Best,
def loadVTPFile(filename):
import vtk
from vtk.util.numpy_support import vtk_to_numpy
from vtk.util import numpy_support as npvtk
reader = vtk.vtkXMLPolyDataReader()
reader.SetFileName(filename)
reader.Update()
data = reader.GetOutput()
points = data.GetPoints()
npts = points.GetNumberOfPoints()
x = vtk_to_numpy(points.GetData())
triangles= vtk_to_numpy(data.GetPolys().GetData())
ntri = triangles.size // 4 # number of cells
tri = np.take(triangles,[n for n in range(triangles.size) if n%4 != 0]).reshape(ntri,3)
n_arrays = reader.GetNumberOfPointArrays()
for i in range(n_arrays):
print(reader.GetPointArrayName(i))
X = vtk_to_numpy(points.GetData())
x=X[:,0]
y=X[:,1]
z=X[:,2]
# Define the velocity components U=(u,v,w)
U = vtk_to_numpy(data.GetPointData().GetArray('UMean'))
u = U[:,0]
v = U[:,1]
w = U[:,2]
magU=np.sqrt(u**2+v**2+w**2)
p = vtk_to_numpy(data.GetPointData().GetArray('pMean'))
Ma = vtk_to_numpy(data.GetPointData().GetArray('MaMean'))
rho = vtk_to_numpy(data.GetPointData().GetArray('rhoMean'))
return x,y,z,u,v,w,magU,p,Ma,rho,tri
1st: Paraview vtp slice via matplotlib:
Paraview vtp slice via matplotlib
2nd image OpenFOAM cut via libsampling
2nd image OpenFOAM cut via libsampling
Thanks for your help
OpenFOAM vtp slice export:
cellPoint, triangulated true/false, interpolated true/false and so on...

Shortest rotation between two vectors not working like expected

def signed_angle_between_vecs(target_vec, start_vec, plane_normal=None):
start_vec = np.array(start_vec)
target_vec = np.array(target_vec)
start_vec = start_vec/np.linalg.norm(start_vec)
target_vec = target_vec/np.linalg.norm(target_vec)
if plane_normal is None:
arg1 = np.dot(np.cross(start_vec, target_vec), np.cross(start_vec, target_vec))
else:
arg1 = np.dot(np.cross(start_vec, target_vec), plane_normal)
arg2 = np.dot(start_vec, target_vec)
return np.arctan2(arg1, arg2)
from scipy.spatial.transform import Rotation as R
world_frame_axis = input_rotation_object.apply(canonical_axis)
angle = signed_angle_between_vecs(canonical_axis, world_frame_axis)
axis_angle = np.cross(world_frame_axis, canonical_axis) * angle
C = R.from_rotvec(axis_angle)
transformed_world_frame_axis_to_canonical = C.apply(world_frame_axis)
I am trying to align world_frame_axis to canonical_axis by performing a rotation around the normal vector generated by the cross product between the two vectors, using the signed angle between the two axes.
However, this code does not work. If you start with some arbitrary rotation as input_rotation_object you will see that transformed_world_frame_axis_to_canonical does not match canonical_axis.
What am I doing wrong?
not a python coder so I might be wrong but this looks suspicious:
start_vec = start_vec/np.linalg.norm(start_vec)
from the names I would expect that np.linalg.norm normalizes the vector already so the line should be:
start_vec = np.linalg.norm(start_vec)
and all the similar lines too ...
Also the atan2 operands are not looking right to me. I would (using math):
a = start_vec / |start_vec | // normalized start
b = target_vec / |target_vec| // normalized end
u = a // normalized one axis of plane
v = cross(u ,b)
v = cross(v ,u)
v = v / |v| // normalized second axis of plane perpendicular to u
dx = dot(u,b) // target vector in 2D aligned to start
dy = dot(v,b)
ang = atan2(dy,dx)
beware the ang might negated (depending on your notations) if the case either add minus sign or reverse the order in cross(u,v) to cross(v,u) Also you can do sanity check with comparing result to unsigned:
ang' = acos(dot(a,b))
in absolute values they should be the same (+/- rounding error).

How do I store an integer input from the user into a variable in Tkinter?

For my Python class were using turtle graphics.
We have too draw a target that appears at a random location on the screen. Got that.
Then a pop up window appears asking for what you think the coordinates of the target are. First the pop up box asks you to enter the x coordinate then it asks you to enter the y coordinate.
I'm having trouble saving the users inputed integers from my Tkinter window into variables I can use later in the program.
from Tkinter import *
window = Tk()
window.title("Player Input")
window.geometry('+350+130')
thexinput = IntVar()
L1 = Label(window, text="Enter the x coordinate for Mike")
L1.pack( side = LEFT)
E1= Entry(window, textvariable= thexinput, bd =5)
E1.pack(side = RIGHT)
def userinput():
global inp
a = raw_input(thexinput.get())
inp = a
b = Button(window, text = 'Submit', command = userinput)
b.pack(side = BOTTOM)
window.mainloop()
You don't need to use raw_input, you just need to call the get method of the entry widget.
a = thexinput.get()

Description of parameters of GDAL SetGeoTransform

Can anyone help me with parameters for SetGeoTransform? I'm creating raster layers with GDAL, but I can't find description of 3rd and 5th parameter for SetGeoTransform. It should be definition of x and y axis for cells. I try to find something about it here and here, but nothing.
I need to find description of these two parameters... It's a value in degrees, radians, meters? Or something else?
The geotransform is used to convert from map to pixel coordinates and back using an affine transformation. The 3rd and 5th parameter are used (together with the 2nd and 4th) to define the rotation if your image doesn't have 'north up'.
But most images are north up, and then both the 3rd and 5th parameter are zero.
The affine transform consists of six coefficients returned by
GDALDataset::GetGeoTransform() which map pixel/line coordinates into
georeferenced space using the following relationship:
Xgeo = GT(0) + Xpixel*GT(1) + Yline*GT(2)
Ygeo = GT(3) + Xpixel*GT(4) + Yline*GT(5)
See the section on affine geotransform at:
https://gdal.org/tutorials/geotransforms_tut.html
I did do like below code.
As a result I was able to do same with SetGeoTransform.
# new file
dst = gdal.GetDriverByName('GTiff').Create(OUT_PATH, xsize, ysize, band_num, dtype)
# old file
ds = gdal.Open(fpath)
wkt = ds.GetProjection()
gcps = ds.GetGCPs()
dst.SetGCPs(gcps, wkt)
...
dst.FlushCache()
dst = Nonet
Given information from the aforementioned gdal datamodel docs, the 3rd & 5th parameters of SatGeoTransform (x_skew and y_skew respectively) can be calculated from two control points (p1, p2) with known x and y in both "geo" and "pixel" coordinate spaces. p1 should be above-left of p2 in pixelspace.
x_skew = sqrt((p1.geox-p2.geox)**2 + (p1.geoy-p2.geoy)**2) / (p1.pixely - p2.pixely)`
y_skew = sqrt((p1.geox-p2.geox)**2 + (p1.geoy-p2.geoy)**2) / (p1.pixelx - p2.pixelx)`
In short this is the ratio of Euclidean distance between the points in geospace to the height (or width) of the image in pixelspace.
The units of the parameters are "geo"length/"pixel"length.
Here is a demonstration using the corners of the image stored as control points (gcps):
import gdal
from math import sqrt
ds = gdal.Open(fpath)
gcps = ds.GetGCPs()
assert gcps[0].Id == 'UpperLeft'
p1 = gcps[0]
assert gcps[2].Id == 'LowerRight'
p2 = gcps[2]
y_skew = (
sqrt((p1.GCPX-p2.GCPX)**2 + (p1.GCPY-p2.GCPY)**2) /
(p1.GCPPixel - p2.GCPPixel)
)
x_skew = (
sqrt((p1.GCPX-p2.GCPX)**2 + (p1.GCPY-p2.GCPY)**2) /
(p1.GCPLine - p2.GCPLine)
)
x_res = (p2.GCPX - p1.GCPX) / ds.RasterXSize
y_res = (p2.GCPY - p1.GCPY) / ds.RasterYSize
ds.SetGeoTransform([
p1.GCPX,
x_res,
x_skew,
p1.GCPY,
y_skew,
y_res,
])

Import rotation from file MaxScript

How I can import rotation from file? I need Quaternions
Currently I can only import object location.
Structure of txt file:
x,y,z,xrot,yrot,zrot,wrot,nameofobject
Here is my script:
(
file = memStreamMgr.openFile #"C:\test.txt"
while NOT file.eos() do
(
local line = filterString (file.readLine()) ", "
if line.count == 8 AND isValidNode (local obj = getNodeByName line[8]) do
obj.pos = [line[1] as float, line[2] as float, line[3] as float]
)
memStreamMgr.close file
)
Since the only thing that changed since your last question is the structure of the text file, I presume you are creating it yourself – if that is the case, change the comma to a different separator, for example a pipe, and save complete node transform matrix. Anyway, to answer your question as it stands, instead of setting position, set the transform like this:
obj.transform = translate (quat xrot yrot zrot wrot as matrix3) [x, y, z]