1
$\begingroup$

I have several points' coordinate that constructed one polygon. I want to scale this polygon with a point inside the polygon and get points' coordinates after scaling. like this

$\endgroup$
6
  • $\begingroup$ build-in addon: Mesh Tools > Offset Edges code.it4i.cz/blender/blender-addons/-/blob/… $\endgroup$
    – X Y
    May 19 at 11:54
  • $\begingroup$ @XY op is asking for how to do this via python, also asking how to get vert locs after the transform. $\endgroup$
    – Jakemoyo
    May 19 at 12:02
  • $\begingroup$ Not sure if the asker knows the coordinates of the geometric center. $\endgroup$
    – X Y
    May 19 at 12:25
  • $\begingroup$ @XY Yes the center coordinates is prepared. $\endgroup$ May 19 at 12:42
  • $\begingroup$ @Winertoz Botawar So, did the answer solve your problem? $\endgroup$
    – X Y
    May 19 at 12:50

1 Answer 1

1
$\begingroup$

Something like this should work.

import pprint as pp
import bpy
import bmesh
from mathutils import Vector

# object needs to be in edit mode for this exact
# technique to work. There are other ways to 
# get access to the vert data but this is
# one of the quicker ways.

obj = bpy.context.active_object
mesh = obj.data
bm = bmesh.from_edit_mesh(mesh)

# vector to scale the verts by
scale_amt = Vector((2,2,0))

vert_locs_current = [v.co for v in bm.verts]
pp.pprint(vert_locs_current)

#[Vector((-5.449918746948242, -3.937771797180176, 0.0)),
# Vector((2.550081729888916, -2.3869245052337646, 0.0)),
# Vector((-5.449918746948242, 4.062228202819824, 0.0)),
# Vector((2.550081729888916, 2.511380434036255, 0.0)),
# Vector((-8.69951057434082, 0.3733687400817871, 0.0))]

# loop through the vertices
for v in bm.verts:
    # scaling them uniformly is the same as just 
    # multiplying their current coordinates by a Vector
    v.co *= scale_amt
    
# this is so the new vert locations can be seen in
# the viewport
bmesh.update_edit_mesh(mesh)

vert_locs_new = [v.co for v in bm.verts]
pp.pprint(vert_locs_new)

#[Vector((0.16568545997142792, 1.999999761581421, 0.0)),
# Vector((-1.8343143463134766, -1.827902167406137e-07, 0.0)),
# Vector((0.16568563878536224, -2.0, 0.0)),
# Vector((1.5798989534378052, -1.41421377658844, 0.0)),
# Vector((1.5798993110656738, 1.4142131805419922, 0.0))]
```
$\endgroup$
2
  • $\begingroup$ This is the before and after of my script overlaid over eachother, I think it's something to do with you script that's not related. Are you sure you're using *= and not *+=` anywhere you're manipulating coordinates? $\endgroup$
    – Jakemoyo
    May 19 at 13:02
  • $\begingroup$ Note that this script requires the object to be in edit mode. $\endgroup$ May 19 at 18:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.