# yade-users team mailing list archive

## Re: [Question #697545]: How to create a cylinder model with hard and soft interlayer

 Thread Previous • Date Previous • Date Next • Thread Next

```Question #697545 on Yade changed:

Jan Stránský proposed the following answer:
The posted code was meant to present one option how to do it, with very easy isSoftRockParticle condition.
You can substitute whatever instead of this "z in (1.5;2.5) range".

If your region is bounded by two parallel planes [2], you can easily do something like:
###
normal = Vector3(1,0,4)
def plane(x,y,z,d):
nx,ny,nz = normal
return nx*x + ny*y + nz*z + d
def plane1(x,y,z): # equation of "lower" plane
return plane(x,y,z,2)
def plane2(x,y,z): # equation of "upper" plane
return plane(x,y,z,3)
def isSoftRockParticle(b):
x,y,z = b.state.pos
p1 = plane1(x,y,z)
p2 = plane2(x,y,z)
return p1 > 0 and p2 < 0
# p1 > 0 ... (x,y,z) is "above" the "lower" plane
# p2 < 0 ... (x,y,z) is "below" the "upper" plane
###

For more complicated situations (or to make your solution easier to extend / maintain / read / ...), you can use Yade predicates [3,4], e.g. pack.inHalfSpace [5]:
###
normal = Vector3(1,0,4)
halfSpace1 = pack.inHalfSpace((0,0,3),+normal) # pack.inHalfSpace(point,normal direction)
halfSpace2 = pack.inHalfSpace((0,0,3),-normal)
predicate = halfSpace1 & halfSpace2 # intersection
def isSoftRockParticle(b):
pos = b.state.pos
return predicate(pos,r)
###

As a predicate, you can also use more fancy pack.inGtsSurface [6].

Cheers
Jan

[2] https://en.wikipedia.org/wiki/Plane_(geometry)