Encapsulated bounds center error

Hi, I am trying to encapsulate multiple objets. I need to get capsule size as well as capsule rotation and position. My code is able to get correct size and rotation, but position is sometimes wrong. Here is my code:

private IEnumerator EncapsulateObj()
    {
        Transform trackedTransform = trackedObj.transform;
        _renderers = trackedObj.GetComponentsInChildren<Renderer>();
        if (_renderers.Length == 0)
        {
            _capsule = new Bounds(trackedObj.transform.position, Vector3.zero);
            yield return null;
        }

        Quaternion originalRotation = trackedTransform.rotation;
        trackedTransform.rotation = Quaternion.Euler(0, 0, 0);
        bool foundNotNullRenderer = false;
        if (_renderers.Length > 0)
        {
            for (int i = 0; i < _renderers.Length; i++)
            {
                if (_renderers*)*

if (!foundNotNullRenderer)
{
capsule = renderers*.bounds;
foundNotNullRenderer = true;
continue;
_
}*

capsule.Encapsulate(renderers*.bounds);*
}

}
trackedTransform.rotation = originalRotation;
positionHolder.transform.position = transform.TransformPoint(_capsule.center);
positionHolder.transform.localScale = _capsule.size;
positionHolder.transform.rotation = originalRotation;
}
I guess its problem with pivot but I am not sure how to gix it.
I do place BoxCollider to represent bounding box. Yellow model is trackedTransform.
This is Good capsule [170810-good-box.png|170810]*

And this is wrong [170811-bad-box.png|170811]
Thank you for any suggestions.

_*

ok, so i guess i came up with the solution. Bassically generate 2 bounds, one will hold size, the otherone will hold position. To get size, original code is ok, to get center you won’t rotate objects. It looks like this:
_renderers = trackedObj.GetComponentsInChildren();
if (_renderers.Length == 0)
{
_capsule = new Bounds(trackedObj.transform.position, Vector3.zero);
yield return null;
}
Transform holderTransform = positionHolder.transform;
holderTransform.position = Vector3.zero;

        Quaternion originalRotation = trackedObj.rotation;
        bool foundNotNullRenderer = false;
        _capsule = new Bounds();
        Bounds centerBounds = new Bounds(); //to get center
        if (_renderers.Length > 0)
        {
            for (int i = 0; i < _renderers.Length; i++)
            {
                if (_renderers*)*

{
Transform rendTrans = renderers*.transform;
Quaternion originalRot = rendTrans.rotation;
rendTrans.rotation = Quaternion.Euler(0,0,0);
if (!foundNotNullRenderer)
_
{*

capsule = renderers*.bounds;*
foundNotNullRenderer = true;

rendTrans.rotation = originalRotation;
centerBounds = renderers*.bounds;*
continue;
}
capsule.Encapsulate(renderers*.bounds);*
rendTrans.rotation = originalRotation;

centerBounds.Encapsulate(renderers*.bounds);*
}

}
}
holderTransform.position = transform.TransformPoint(centerBounds.center);
holderTransform.localScale = _capsule.size;
holderTransform.rotation = originalRotation;
holderTransform.SetParent(Variables.Objects.initializeTransform.Value.parent);