2
$\begingroup$

I'm trying to create a capsule object in Blender, which consists of two half-spheres and a tube between them, and i need to be able to move it around as if it was a single object and adjust the capsule's diameter and length. I need to link sphere's transforms to the transforms of the middle tube: X\Y scale of the tube should control diameter, Z scale should control length, and of course spheres should inherit location and rotation from it.

So i create the objects:

And add a bunch of drivers to control transform attributes on top and bottom spheres. Now, base location and scale are pretty straight forward. Top sphere's origin matches the origin of the tube, so rotation on it is simple as well. But i'm having a hard time figuring out rotation, or, rather, location of the bottom sphere.

See, i'm changing the location of the bottom sphere based on the length of the tube, so it's origin does not match the origin of the other objects, and if i rotate the capsule, i need to recalculate location of the bottom sphere, as if i was rotating it around a pivot set at top\middle's origin. And i'm having a hard time wrapping my head around how to do that.

I remember writing code to draw a cube in the past, and there i used angle addition trig formulas to calculate verts locations after rotation. Say, if i was to rotate the cube around the Z axis, X coordinate would change like:

X' = cos(rz)*X - sin(rz)*Y

and so on. But here i need to apply all rotations at once, and i can't figure it out. I can get rotations working in one or two planes, but not all three. And the more i've been thinking about, the more confused i get.

Now i'm sure that Blender has some functions to calculate that stuff, but it's not like i can use them in a driver, what i need is an actual math expression. I tried searching, but my googling skills seem to fail me as well, as i haven't been able to find what i need either. Can anyone who's familiar with the math involved in such calculations help me out with this?

Edit:

Calculating dot product by this matrix seems to work. For anyone who might be wondering how to do something similar this is what i have in driver expressions right now:

botLoc[0].driver.expression = "(-len * (sin(rx)*sin(rz)+cos(rx)*sin(ry)*cos(rz)))"

botLoc[1].driver.expression = "(-len * (-sin(rx)*cos(rz)+cos(rx)*sin(ry)*sin(rz)))"

botLoc[2].driver.expression = "(-len * (cos(rx)*cos(ry)))"

where rx\ry\rz are variables containing rotations, and len is the middle section z scale.

$\endgroup$
7
  • 1
    $\begingroup$ I think we have to exclude an XY Problem here. Can we know the final purpose of this object? (There are quite a few easier ways to do this than scripting, drivers) $\endgroup$
    – Robin Betts
    Feb 3 at 11:14
  • $\begingroup$ I think what you are looking for is this : Rotation formalisms in three dimensions ? But as stated by Robin Betts, Blender offers far more elegant ways to achieve such results. $\endgroup$ Feb 3 at 11:24
  • 1
    $\begingroup$ Agree with the others. Why are you using more than one object? It would be much easier to create your capsule object from a sphere in the first place and then set its origin to the geometry if necessary. $\endgroup$
    – John Eason
    Feb 3 at 11:37
  • $\begingroup$ The purpose is to have a representation of a capsule object, the dimensions of which could be changed by adjust two values without editing the mesh. $\endgroup$
    – Moff
    Feb 3 at 11:50
  • $\begingroup$ Geometry node could do in a more simple way, maybe. Is it possible to use it in your context? $\endgroup$
    – lemon
    Feb 3 at 12:03

3 Answers 3

5
$\begingroup$

You could also do this with a couple of modifiers, and shape-keys, on a mesh Cylinder.

  1. An over-the-top width Bevel, Shape 0.5, with 'Clamp Overlap'
  2. A Weld, to get rid of the duplicate vertices at the poles
  3. Maybe a Subdivision Surface

To bias the circumference loops towards the tips under Subdiv, to improve the interpolation of normals, you can give the edges around the caps a Crease.

Then you can give your Cylinder shape-keys; a scale in Z and a scale in XY. Those can be your keyable inputs to change the thickness and length of your capsule:

enter image description here

$\endgroup$
6
  • 1
    $\begingroup$ or with bones, possibly... $\endgroup$
    – lemon
    Feb 3 at 18:53
  • $\begingroup$ Great! I tried something involved Array modifier + caps + merging, but I had some artifacts and figured it's not worth it trying to make it work... In my and lemon's answers I'd still advise to start with low topo and use catmul clark subdivision to get 2nd derivative smoothness... $\endgroup$ Feb 3 at 18:58
  • 1
    $\begingroup$ so finally, XY.... $\endgroup$
    – lemon
    Feb 3 at 18:59
  • $\begingroup$ @MarkusvonBroady .. I guess, maybe, you'd really want round-cube caps to avoid the poles, and a nice nearby fixed loop to set up the normal interp. down the length .. that feels more like a GN thing to me. $\endgroup$
    – Robin Betts
    Feb 3 at 19:08
  • 1
    $\begingroup$ I can't stop laughing at this GIF for some reason $\endgroup$
    – Sam Estep
    Feb 3 at 23:24
4
$\begingroup$

I don't know if that fits all your project constraints, but that can be the following using geometry nodes.

enter image description here

enter image description here

Make a sphere. Remove bottom half part.

Rotate it 180 and shift it down.

Shift again but up.

Make a cylinder.

Join and merge them all.

(Blender 4.0)

$\endgroup$
2
  • $\begingroup$ Thanks, this does look more convenient than what i'm doing. I'll look into it. $\endgroup$
    – Moff
    Feb 3 at 12:31
  • $\begingroup$ note that you could use your own capsule models and also add materials. $\endgroup$
    – lemon
    Feb 3 at 12:32
4
$\begingroup$

An iteration on lemon's answer:

$\endgroup$
1
  • $\begingroup$ Thanks. Can't say that i need much fine-tuning for my purposes, but it's nice to have an example. $\endgroup$
    – Moff
    Feb 3 at 13:03

You must log in to answer this question.

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