Move or scale a facet

Asked by gaoxuesong on 2019-06-11

How to move or scale a facet? In my opinion, 1. get the 3 vertices of the facet. 2. give a increment to x coordinate of the 3 vertices (e.g., move in x direction). 3. the facet move automatically, if not, use the new vertices to generate a new facet and remove the old one.
But i find the vertices obtained by the method of 'body.shape.vertices' are not the vertices i use to define the facet.
Here is the codes,
### define a facet using 3 points
v1 =(0,0,0)
v2 = (1,0,0)
v3 =(1,1,0)
f1 = facet((v1,v2,v3),wire=False)
O.bodies.append(f1)

### get the vertices of the facet
for eb in O.bodies:
    print(eb.state.pos)
    print(eb.shape.vertices)

The result is,
Vector3(0.7071067811865475,0.2928932188134525,0)
[Vector3(-0.7071067811865475,-0.2928932188134525,0), Vector3(0.29289321881345254,-0.2928932188134525,0), Vector3(0.29289321881345254,0.7071067811865475,0)]

So what is the meaning of the 3 vertices? How to move or scale a facet?

Thanks,
Xuesong

Question information

Language:
English Edit question
Status:
Solved
For:
Yade Edit question
Assignee:
No assignee Edit question
Solved by:
gaoxuesong
Solved:
2019-06-12
Last query:
2019-06-12
Last reply:
2019-06-12
Jan Stránský (honzik) said : #1

Hello,

shape.vertices are coordinates in local coordinate system. After a transformation
vGlobal = state.pos + state.ori*vLocal
you get the actual coordinates in global coordinate system.

to move the facet, simply change state.pos or set state.vel with O.step (setting positions directly is not recommended in Yade).

to scale the facets, I think it should be enough to multiply the vertices by the scaling factor (try it and let us know).

cheers
Jan

gaoxuesong (260582472-9) said : #2

Thanks. I have tried to move and scale a facet. For moving a facet, just changing the position is feasible. But for scaling a facet, just multiplying a scaling factor is not feasible. The vertice coordinates can not be changed directly, like the tuple and string in python, i think.
Following is the code i used,

from yade import qt
c = qt.Controller()
O.bodies.clear()
### 2 initial facet ###
v1 =(0,0,0)
v2 = (1,0,0)
v3 =(1,1,0)
f1 = facet((v1,v2,v3),wire=False)
O.bodies.append(f1)
v1 =(2,0,0)
v2 = (3,0,0)
v3 =(3,1,0)
f1 = facet((v1,v2,v3),wire=False)
O.bodies.append(f1)

## move facet 1
fcet1 = O.bodies[0]
mv = (1,0,0)
fcet1.state.pos += mv
## succeed ###
## scale vertices
for ev in fcet1.shape.vertices:
    for i in range(3):
        ev[i] *= 0.5
## failed, the vertices can not be changed
## then try to construct a new facet using the scaled and translated vertices
vg = []
for ev in fcet1.shape.vertices:
    vgi = fcet1.state.pos+fcet1.state.ori*ev ## global coordinates
    vg.append(vgi)
print(vg)
for each in vg:
    for i in range(3):
        each[i] *= 0.5
        if i == 1: ## translate in y direction by 2.0
            each[i] += 2.0
print(vg)
## construct the new facet and remove the old one
f1 = facet((vg[0],vg[1],vg[2]),wire=False)
O.bodies.append(f1)
O.bodies.erase(fcet1.id)

Jan Stránský (honzik) said : #3

Hello,

> just multiplying a scaling factor is not feasible. The vertice coordinates can not be changed directly

the vertices can be changes, but they must be set at once (similar to setting one component of b.state.pos)

###
b = Body()
print b.state.pos
b.state.pos[0] = 1 # does not work
print b.state.pos
b.state.pos = (1,0,0) # works
print b.state.pos
###

for your case:
###
v1 =(0,0,0)
v2 = (1,0,0)
v3 =(1,1,0)
f1 = facet((v1,v2,v3),wire=False)
O.bodies.append(f1)
print f1.shape.vertices
print [f1.state.pos + f1.state.ori*v for v in f1.shape.vertices]

# move facet 1
f1 = O.bodies[0]
mv = (1,0,0)
f1.state.pos += mv
print f1.shape.vertices
print [f1.state.pos + f1.state.ori*v for v in f1.shape.vertices]

# scale vertices
vs = f1.shape.vertices # original vertices
vs = [v*0.5 for v in vs] # scaled vertices
f1.shape.vertices = vs # vertices set at once
print f1.shape.vertices
print [f1.state.pos + f1.state.ori*v for v in f1.shape.vertices]
###

cheers
Jan

gaoxuesong (260582472-9) said : #4

Yes, you are right. Much thanks.

Chareyre (bruno-chareyre-9) said : #5

Hi,
If your plan is to have deforming facets (over time) scaling will not work
since time integration for facets assume a rigid body.

If it is your case PFacets should be considered since it reflects nodes
motion across the facet area.

If scaling is just a way to set an initial geometry then the above is ok.
Bruno

Le mer. 12 juin 2019 17:43, gaoxuesong <email address hidden>
a écrit :

> Question #681341 on Yade changed:
> https://answers.launchpad.net/yade/+question/681341
>
> Status: Answered => Solved
>
> gaoxuesong confirmed that the question is solved:
> Thanks. I have tried to move and scale a facet. For moving a facet, just
> changing the position is feasible. But for scaling a facet, just
> multiplying a scaling factor is not feasible. The vertice coordinates can
> not be changed directly, like the tuple and string in python, i think.
> Following is the code i used,
>
> from yade import qt
> c = qt.Controller()
> O.bodies.clear()
> ### 2 initial facet ###
> v1 =(0,0,0)
> v2 = (1,0,0)
> v3 =(1,1,0)
> f1 = facet((v1,v2,v3),wire=False)
> O.bodies.append(f1)
> v1 =(2,0,0)
> v2 = (3,0,0)
> v3 =(3,1,0)
> f1 = facet((v1,v2,v3),wire=False)
> O.bodies.append(f1)
>
> ## move facet 1
> fcet1 = O.bodies[0]
> mv = (1,0,0)
> fcet1.state.pos += mv
> ## succeed ###
> ## scale vertices
> for ev in fcet1.shape.vertices:
> for i in range(3):
> ev[i] *= 0.5
> ## failed, the vertices can not be changed
> ## then try to construct a new facet using the scaled and translated
> vertices
> vg = []
> for ev in fcet1.shape.vertices:
> vgi = fcet1.state.pos+fcet1.state.ori*ev ## global coordinates
> vg.append(vgi)
> print(vg)
> for each in vg:
> for i in range(3):
> each[i] *= 0.5
> if i == 1: ## translate in y direction by 2.0
> each[i] += 2.0
> print(vg)
> ## construct the new facet and remove the old one
> f1 = facet((vg[0],vg[1],vg[2]),wire=False)
> O.bodies.append(f1)
> O.bodies.erase(fcet1.id)
>
> --
> You received this question notification because your team yade-users is
> an answer contact for Yade.
>
> _______________________________________________
> Mailing list: https://launchpad.net/~yade-users
> Post to : <email address hidden>
> Unsubscribe : https://launchpad.net/~yade-users
> More help : https://help.launchpad.net/ListHelp
>
>
>