I have tried many different things but I have not found a way to infer to the point selected by red circle.
You're looking for BoundingBox.corner(n) in which n:
0 = [0, 0, 0] (left front bottom)
1 = [1, 0, 0] (right front bottom)
2 = [0, 1, 0] (left back bottom)
3 = [1, 1, 0] (right back bottom)
4 = [0, 0, 1] (left front top)
5 = [1, 0, 1] (right front top)
6 = [0, 1, 1] (left back top)
7 = [1, 1, 1] (right back top))
If you group is your Group and you want the left front bottom corner::
group.local_bounds.corner(0)
Related
Hello I am working on a quick sort example using python, and I have trouble understanding the workflow of the following code. Can anyone give me some advice?
From the below code, if the line with the '# Question 1' comment is true and 'return', why the program goes to 'quicksort(array, start, right-1)' next not exiting the function quicksort(array, start, end) nor going to the quicksort(array, right + 1, end)?
Also, then, when this line, 'quicksort(array, right+1, end)', is called?
array = [5, 7, 9, 0, 3, 1, 6, 2, 4, 8]
def quicksort(array, start, end):
if start >= end: # Question 1
return
pivot = start
left = start + 1
right = end
while left <= right:
while left <= end and array[left] <= array[pivot]:
left += 1
while right > start and array[right] >= array[pivot]:
right -= 1
if left > right: # Question 2
array[pivot], array[right] = array[right], array[pivot]
else:
array[right], array[left] = array[left], array[right]
quicksort(array, start, right - 1)
quicksort(array, right + 1, end)
quicksort(array, 0, len(array) - 1)
print(array)
I have debugged the program in pycharm but still couldn't understand.
I'm trying to make this plot for the Ćukasiewicz t-norm
and I don't know how to make the z axis go only from 0 to 1,
mine goes from -1 to 1 and I need that flat area to be visible.
Now I have
def luka_tnorm(a, b):
c = a + b - 1
return max(c, 0)
plot3d(luka_tnorm(a, b), (a, 0, 1), (b, 0, 1))
My plot now looks like this
Try this:
sage: plot3d(luka_tnorm, (0, 1), (0, 1))
Launched html viewer for Graphics3d Object
sage: plot3d(luka_tnorm, (0, 1), (0, 1), mesh=True)
Launched html viewer for Graphics3d Object
Assuming I have a vector of say four dimensions in which every variable lays in a special interval. Thus we got:
Vector k = (x1,x2,x3,x4) with x1 = (-2,2), x2 = (0,2), x3 = (-4,1), x4 = (-1,1)
I am only interested in the points constraint by the intervals.
So to say v1 = (0,1,2,0) is important where v2 = (-5,-5,5,5) is not.
In additon to that the point i+1 should be relatively close to point i among my journey. Therefore I dont want to jump around in space.
Is there a proper way of walking through those interesting points?
For example in 2D space with x1,x2 = (-2,2) like so:
Note: The frequenz of the red line could be higher
There are many ways to create a space-filling curve while preserving closeness. See the Wikipedia article for a few examples (some have associated algorithms for generating them): https://en.wikipedia.org/wiki/Space-filling_curve
Regardless, let's work with your zig-zag pattern for 2D and work on extending it to 3D and 4D. To extend it into 3D, we just add another zig to the zig-zag. Take a look at the (rough) diagram below:
Essentially, we repeat the pattern that we had in 2D but we now have multiple layers that represent the third dimension. The extra zig that we need to add is the switch between bottom-to-top and top-to-bottom every layer. This is pretty simple to abstract:
In 2D, we have x and y axes.
We move across the x domain switching between positive and negative
directions most frequently.
We move across the y domain once.
In 3D, we have x, y, and z axes.
We move across the x domain switching between positive and negative directions most frequently.
We move across the y domain switching between positive and negative directions second most frequently.
We move across the z domain once.
It should be clear how this generalizes to higher dimensions. Now, I'll present some (Python 3) code that implements the zig-zag pattern for 4D. Let's represent the position in 4D space as (x, y, z, w) and the ranges in each dimension as (x0, x1), (y0, y1), (z0, z1), (w0, w1). These are our inputs. Then, we also define xdir, ydir, and zdir to keep track of the direction of the zig-zag.
x, y, z, w = x0, y0, z0, w0
xdir, ydir, zdir = +1, +1, +1
for iw in range(w1 - w0):
for iz in range(z1 - z0):
for iy in range(y1 - y0):
for ix in range(x1 - x0):
print(x, y, z, w)
x = x + xdir
xdir = -xdir
print(x, y, z, w)
y = y + ydir
ydir = -ydir
print(x, y, z, w)
z = z + zdir
zdir = -zdir
print(x, y, z, w)
w = w + 1
This algorithm has the guarantee that no two points printed out after each other have a distance greater than 1.
Using recursion, you can clean this up to make a very nice generalizable method. I hope this helps; let me know if you have any questions.
With the work of #Matthew Miller I implemented this generalization for any given multidimenisonal space:
'''assuming that we take three points out of our intervals [0,2] for a,b,c
which every one of them is corresponding to one dimension i.e. a 3D-space'''
a = [0,1,2]
b = [0,1,2]
c = [0,1,2]
vec_in = []
vec_in.append(a)
vec_in.append(b)
vec_in.append(c)
result = []
hold = []
dir = [False] * len(vec_in)
def create_points(vec , index, temp, desc):
if (desc):
loop_x = len(vec[index])-1
loop_y = -1
loop_z = -1
else:
loop_x = 0
loop_y = len(vec[index])
loop_z = 1
for i in range(loop_x,loop_y,loop_z):
temp.append(vec[index][i])
if (index < (len(vec) - 1)):
create_points(vec, index + 1, temp, dir[index])
else:
u = []
for k in temp:
u.append(k)
result.append(u)
temp.pop()
if (dir[index] == False):
dir[index] = True
else:
dir[index] = False
if len(temp) != 0:
temp.pop()
#render
create_points(vec_in, 0, hold, dir[0])
for x in (result):
print(x)
The result is a journey which covers every possible postion in a continous way:
[0, 0, 0]
[0, 0, 1]
[0, 0, 2]
[0, 1, 2]
[0, 1, 1]
[0, 1, 0]
[0, 2, 0]
[0, 2, 1]
[0, 2, 2]
[1, 2, 2]
[1, 2, 1]
[1, 2, 0]
[1, 1, 0]
[1, 1, 1]
[1, 1, 2]
[1, 0, 2]
[1, 0, 1]
[1, 0, 0]
[2, 0, 0]
[2, 0, 1]
[2, 0, 2]
[2, 1, 2]
[2, 1, 1]
[2, 1, 0]
[2, 2, 0]
[2, 2, 1]
[2, 2, 2]
Example:
I have a solution list a:
a = [1, 1, 0, 0, 0]
and input lists bs:
b1 = [1, 1, 0, 0, 0]
b2 = [0, 1, 1, 0, 0]
b3 = [0, 0, 1, 1, 0]
...
bn = [1, 0, 0, 0, 1]
If I compare a to either b1, b2, ..., bn, I expected to get True value from the comparisons. For sure, this simple expression will not work:
if a == b:
...
because in Python only identical lists can be equal.
Is there any beautiful math that I can easily implement it in programming languages? Now I am thinking about building some hash function but I'm still not sure how?
Note 1) it can be easily implemented by just using for loop but I need some thing more robust. 2) this is maybe also related to problem of this post Cyclic group
A simple solution could be to adjust the a and b values:
a_original = [5, 2, 3, 1, 4]
a_formatted = sorted(a_original)
Then, you can just use the formatted variables. A simple "for" loop can be used to format all of your variables.
Hope this helps!
I have a grass texture:
I use it in my 2d-game. I want to animate it by code, without any predefined animations.
The grass should interact with wind. So when the wind is stronger, the grass should stoop into need side more.
First version of animation I made using sinusoid function, but such animation is a bit ugly, because the base of the grass moves left/right like all another part of picture. And with sinusoid I'm not able to regulate stoop of the image.
Any advices?
This is what you may get easily by shifting pixels:
Although probably not very useful for you, here is a Mathematica program:
f[l_, sh_] := Module[{c = l, k = (Dimensions#l)[[1]]},
For[i = 1, i <= k, i++,
c[[i]] = RotateRight[l[[i]], IntegerPart[(k + 1 - i)/sh]]];
Return[c];]
b = ArrayPad[ImageData#a, {{40}, {40}, {0}}, {1, 1, 1}];
Export["c:\\anim.gif",
{Image#b, Image#f[b, 7],
Image#f[b, 5], Image#f[b, 3],
Image#f[b, 5], Image#f[b, 7], Image#b}, "DisplayDurations" -> .3]
Edit
But you can get a better effect by applying a circular transform:
b = Image#ArrayPad[ImageData#a, {{40, 0}, {40}, {0}}, {1, 1, 1}];
f[image_, angleMult_] := ImageForwardTransformation[image, (
fi = ArcTan[Abs[#[[2]]/(#[[1]] - .5)]];
fi1 = angleMult fi (#[[1]]^2 + #[[2]]^2)/2;
{(1/2 - Sin[fi1] #[[2]] - Cos[fi1]/2 +
Cos[fi1] #[[1]]), -Sin[fi1]/2 + Sin[fi1] #[[1]] +
Cos[fi1] #[[2]]}) &]
t = Table[f[b, x], {x, 0, .2, .02}];
t1 = Reverse#t;
Export["c:\\anim.gif", Join[t, t1], "DisplayDurations" -> .15];
Import["c:\\anim.gif", "Animation"]
You could just shift the rows, so that e.g. every 3rd row is shifted 1px to the right, beginning with the bottom.
How are you displaying the texture? When using a billboard you could manipulate the vertices of the billboard and even triangulate the billboard for more control.