How to use a weight to check if an object is stable?

Blender Asked on November 26, 2020

Let’s say that you have a table with randomly generated legs, and that you want to check if the table is stable enough to stand with a weights placed, one at a time, in four different spots on the board.

enter image description here

Question 1: How do you get the coordinates for these 4 different spots?

The best way would to be able to refer to each position as positions on the board rather than numbers , so that future scaling of the board doesn’t affect the weights positions in relation to the board.

So let’s say that you are able to identify the 4 locations. You create 4 cubes based on those postions:

bpy.ops.mesh.primitive_cube_add(radius=0.1, location=(location1))
bpy.ops.mesh.primitive_cube_add(radius=0.1, location=(location2))
bpy.ops.mesh.primitive_cube_add(radius=0.1, location=(location3))
bpy.ops.mesh.primitive_cube_add(radius=0.1, location=(location3))

However, you want to test if the table stands one cube at the time. You want to be able to unlink all cubes, then link back cube 1 to check, unlink and link back cube 2 and so on, till all four cubes are tested.
How do you unlink and link back the cubes?

One Answer

Ok, so I think I found a solution

def create_cubes():
#board=table without the legs
#First cube
bpy.ops.mesh.primitive_cube_add(radius=r, location=(l.x-d.x/2+3*r, l.y+d.y/2-3*r, h+d.z+r))
cube1=bpy.context.active_object = "Cube" + str(1)
validation_cubes.append(cube1)['Scene'].objects.unlink(["Cube" + str(1)])
#Second cube
bpy.ops.mesh.primitive_cube_add(radius=r, location=(l.x, l.y+d.y/2-2*r, h+d.z+r))
cube2=bpy.context.active_object = "Cube" + str(2)
validation_cubes.append(cube2)['Scene'].objects.unlink(["Cube" + str(2)])    
#Third cube
bpy.ops.mesh.primitive_cube_add(radius=r, location=(l.x+d.x/4, l.y-d.y/2+3*r, h+d.z+r))
cube3=bpy.context.active_object = "Cube" + str(3)
validation_cubes.append(cube3)['Scene'].objects.unlink(["Cube" + str(3)])   

Now you have defined the locations for three cubes. These locations will be the same, no matter how you scale the board or the radius of the cube.The cubes are named and placed in the list validation_cubes, unliked from the mesh

Then you simply need to create a loop that links back each cube, one at a time, so that the cubes don't affect eachother

def validate_table():
for x in range(0,3):['Scene'][validation_cubes[x].name])

Answered by Jesper on November 26, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP