Calculating anchors for randomized placement of child Game Objects in parent

Building off my last question found here , I am trying to figure out how to calculate the anchors for a bunch of child game objects Game Objects to ensure they stay within the bounds of their parent.

First, I calculate what the width & height of the parent should be with the following:

public void CalculateParentContainer(RectTransform container, StarSystem[] systems)
    {
        minX = maxX = minY = maxY = 0;

        for (int i = 0; i < systems.Length; i++)
        {
            // The locations are chosen at random, ensuring overlap doesn't happen. Also scale is a public field, which is the zoom level of the container.
            float tempMinX = (float)systems[i].Location.X * scale;
            float tempMaxX = (float)systems[i].Location.X * scale;
            float tempMinY = (float)systems[i].Location.Y * scale;
            float tempMaxY = (float)systems[i].Location.Y * scale;

            if (tempMinX < minX) { minX = tempMinX; }
            if (tempMaxX > maxX) { maxX = tempMaxX; }
            if (tempMinY < minY) { minY = tempMinY; }
            if (tempMaxY > maxY) { maxY = tempMaxY; }

        }
        container.sizeDelta = new Vector2((maxX - minX) + starSystemRadius*2 , (maxY - minY) + starSystemRadius*2);

This gives me the proper dimensions, but as someone points out in my previous post (see link at top), that the AABB of the points don’t represent the actual center of the parent and so there’s usually a weird offset at the left and bottom bounds of the parent, which effectively cut off the view of some points. See image.

After messing around with RectTransforms a bit, I noticed that if I change the anchors of the child game objects, I can make the children fit into the parent, but thats because I literally hard-coded the values in, as so:

// This is run through a loop for each 'star system' which contains its randomized location
private GameObject CreateCircleSprite(Vector3 anchoredPos, int index, StarType type)
    {
        GameObject circleGameObj = new GameObject("system", typeof(Image));
        circleGameObj.transform.SetParent(mapContainer);

        // Other stuff, whatever.... 

        RectTransform rectTransform = circleGameObj.GetComponent<RectTransform>();

        // This only works for one seed of the randomized location points
        // HOW DO I CALCULATE THE ANCHORS NEEDED??
        rectTransform.anchorMin = new Vector2(0.4829f, 0.4885f);
        rectTransform.anchorMax = new Vector2(0.4829f, 0.4885f);
        rectTransform.pivot = new Vector2(0.5f, 0.5f);


        // anchoredPosition3D to set the z-axis to 0
        rectTransform.anchoredPosition3D= anchoredPos;
        rectTransform.sizeDelta = new Vector3(starSystemRadius, starSystemRadius, 0);

        rectTransform.localScale = new Vector3(1, 1, 1);

        MapSystemIcon systemIcon = circleGameObj.AddComponent<MapSystemIcon>();
        systemIcon.ID = index;
        systemIcon.OnClick += SystemIcon_OnClick;

        return circleGameObj;
    }

I am guessing that the values I put into anchorMin and anchorMax are the actual center of the parent’s AABB. So my question is, is there a way to calculate the anchors so they represent the parent’s center?

So what’s the goal? You want all of the stars to fit on the screen at one time?

No. The points are in a container (called mapContainer) that has a really large size. The mapContainer is the child of a scroll rect so the user will only ever see a portion of the mapContainer, as allowed by the scroll rect. In the hierarchy, it looks like:

Canvas
| - ScrollRect
| | - mapContainer
| | - all the child points.
| - other things

What i am trying to do is to calculate the anchors of the child points so they stay inside the bounds of the mapContainer.

Can you not use the rect of the mapContainer to get the width/height and make sure the child positions are within those confines?

I personally wouldn’t approach this problem with a scroll rect at all, but using a camera and WorldToScreenPoint to map your UI icons to the world position of your stars. That would get you a very Sins of a Solar Empire feel, which your map reminds me of, with variable zoom levels.