1
$\begingroup$

I have this mesh:

enter image description here

How can I get the object tips position with a python script? Consider I don't want the bounding box tips, but the mesh geometry cusp positions

As dr. Sybren pointed out, there are many ways of defining "tips":

  1. The most extreme points on the axis of the first principal component
  2. The points that touch the bounding sphere/box
  3. The vertices where the curvature of the mesh is over a certain threshold
  4. The points where the highest intensity rays cast from the object center meet the object shape (a generalization of 1.?)
  5. The points where the shape-aligned cutting planes have zero area (similar to 3.?)

(I've added a couple myself). To avoid complicating matter further I'd stick with 2., points that touch the bounding sphere/box.

$\endgroup$
3
  • 1
    $\begingroup$ There are many ways in which to think about your question. How do you define "tips", in a mathematical sense? Are they the most extreme points on the axis of the first principal component? Are they the points that touch the bounding sphere? Or are they defined as vertices where the curvature of the mesh is over a certain threshold? $\endgroup$
    – dr. Sybren
    Commented Mar 10, 2018 at 12:32
  • 1
    $\begingroup$ Or the point where the shape-aligned cutting plane has a zero area? Got to think about it $\endgroup$
    – Kabu
    Commented Mar 10, 2018 at 13:35
  • $\begingroup$ Or the highest intensity rays cast from the object center to the object shape in a spherical space... $\endgroup$
    – Kabu
    Commented Mar 17, 2018 at 11:14

1 Answer 1

1
$\begingroup$

Use the convex hull.

The routine to find the minimum volume bounding box involves the creation of the convex hull. It occurs that the extreme points will be vertices on the convex hull.

Test script. Uses BMesh.ops.convex_hull(...) to create a convex hull mesh where the extreme points will coincide with vertex locations. The two furthest from the origin are chosen and an empty added at those locations. (Assumes the origin is already at center of geometry)

import bpy
import bmesh

context = bpy.context
ob = context.object
me = ob.data
bm = bmesh.new()
bm.from_mesh(me)
ret = bmesh.ops.convex_hull(bm, input=bm.verts)

verts = sorted([v for v in ret["geom"] 
        if isinstance(v, bmesh.types.BMVert)],
        key = lambda v : v.co.length)

for v in verts[-2:]:
    loc = ob.matrix_world * v.co
    bpy.ops.object.empty_add(location=loc)

Notes: simple example above grabs two furthest from origin verts in convex hull. To find the 2nd furthest would find the furthest from the first furthest. Will be arbitrary for something symmetrical like the sphere, where each point is radius from origin.

enter image description here Simple test result on oblong

$\endgroup$
1
  • $\begingroup$ Works perfectly, thank you. I didn't know convex hulls have this use. $\endgroup$
    – Kabu
    Commented Mar 19, 2018 at 21:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .