<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Uniform distribution of objects along the length of the center of plane.]]></title><description><![CDATA[<p dir="auto">Hi all. Please tell me how can I achieve a uniform distribution of cubes along the length of another object, for example, from the center of the plane. The number of cubes is controlled by the number of iterations in the loop.</p>
<p dir="auto">my code:</p>
<pre><code>def main() -&gt; None:
    null = c4d.BaseObject(c4d.Onull)
    
    #Plane
    pl = c4d.BaseObject(c4d.Oplane)
    plW = pl[c4d.PRIM_PLANE_WIDTH] = 200
    plH = pl[c4d.PRIM_PLANE_HEIGHT] = 50
    bbPl = pl.GetRad() # plane Bounding box
    pl.InsertUnder(null)


    #BASE-CUBE
    for i in range(2):

        cube = c4d.BaseList2D(c4d.Ocube)
        xSize = cube[c4d.PRIM_CUBE_LEN,c4d.VECTOR_X] = 50
        ySize = cube[c4d.PRIM_CUBE_LEN,c4d.VECTOR_Y] = 50
        zSize = cube[c4d.PRIM_CUBE_LEN,c4d.VECTOR_Z] = 50
        cube[c4d.ID_BASEOBJECT_REL_POSITION,c4d.VECTOR_Y] = ySize/2
        cube[c4d.ID_BASEOBJECT_REL_POSITION,c4d.VECTOR_X] = ???
        cube.InsertUnder(null)

    return null
    c4d.EventAdd()
</code></pre>
<p dir="auto"><img src="https://developers.maxon.net/forum/assets/uploads/files/1690887826664-e0236f94-86f8-43ce-ab1b-4474186660bf-image.png" alt="e0236f94-86f8-43ce-ab1b-4474186660bf-image.png" class=" img-fluid img-markdown" /></p>
]]></description><link>http://developers.maxon.net/forum/topic/14921/uniform-distribution-of-objects-along-the-length-of-the-center-of-plane</link><generator>RSS for Node</generator><lastBuildDate>Sun, 10 May 2026 08:05:54 GMT</lastBuildDate><atom:link href="http://developers.maxon.net/forum/topic/14921.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 01 Aug 2023 11:03:53 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Uniform distribution of objects along the length of the center of plane. on Tue, 01 Aug 2023 13:16:30 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/ferdinand">@<bdi>ferdinand</bdi></a> Thanks a lot. Very useful information. You are the best!</p>
]]></description><link>http://developers.maxon.net/forum/post/72144</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/72144</guid><dc:creator><![CDATA[SmetK]]></dc:creator><pubDate>Tue, 01 Aug 2023 13:16:30 GMT</pubDate></item><item><title><![CDATA[Reply to Uniform distribution of objects along the length of the center of plane. on Tue, 01 Aug 2023 13:10:06 GMT]]></title><description><![CDATA[<p dir="auto">Hello <a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/smetk">@<bdi>SmetK</bdi></a>,</p>
<p dir="auto">Thank you for reaching out to us. Computing a uniform distribution is a mathematical question and therefore out of scope of support, please refer to Wikipedia and other sources for mathematical concepts. The general answer is linear interpolation, which is of course just another way to say uniform distribution.</p>
<p dir="auto">Note that the Cinema 4D API has no <code>lerp</code> function (abbreviation for linear interpolation), as one might be used to from other APIs. <code>c4d.utils.MixVec</code> provides linear interpolation for vectors and can be used as a standin.</p>
<p dir="auto">I have provided a simple example below.</p>
<p dir="auto">Cheers,<br />
Ferdinand</p>
<p dir="auto">Result:<br />
<img src="https://developers.maxon.net/forum/assets/uploads/files/1690895342273-4c0bef97-993f-4a3b-ac70-c4c15813ab01-image-resized.png" alt="4c0bef97-993f-4a3b-ac70-c4c15813ab01-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">Code:</p>
<pre><code class="language-py">"""Realizes a generator which returns cubes on a plane as its cache.
"""

import c4d

# The size of the plane.
PLANE_SIZE: c4d.Vector  = c4d.Vector(200., 50., 0.)

# The number of cubes.
CUBE_COUNT: int  = 10

# Each cube has the size so that twice #CUBE_COUNT would fit on the plane, i.e., we will place cubes
# with exactly one cube distance on the plane.
CUBE_SIZE: c4d.Vector = c4d.Vector(PLANE_SIZE.x / (CUBE_COUNT * 2),
                                   PLANE_SIZE.x / (CUBE_COUNT * 2),
                                   PLANE_SIZE.x / (CUBE_COUNT * 2))

# The starting and end point of the cube interpolation.
CUBE_POS_A: c4d.Vector = c4d.Vector(-(PLANE_SIZE.x * .5) + (CUBE_SIZE.x * .5), CUBE_SIZE.y *.5, 0)
CUBE_POS_B: c4d.Vector = c4d.Vector(+(PLANE_SIZE.x * .5) - (CUBE_SIZE.x * .5), CUBE_SIZE.y *.5, 0)

def main() -&gt; None:
    """
    """
    # Note that object allocation can fail when you run out of memory.
    null: c4d.BaseObject | None = c4d.BaseObject(c4d.Onull)
    if null is None:
        return
    
    plane: c4d.BaseObject | None  = c4d.BaseObject(c4d.Oplane)
    if plane is None:
        return
    
    # Set the size of the plane
    plane[c4d.PRIM_PLANE_WIDTH] = PLANE_SIZE.x
    plane[c4d.PRIM_PLANE_HEIGHT] = PLANE_SIZE.y
    plane.InsertUnder(null)

    # Generate the cubes.
    for i in range(CUBE_COUNT):
        cube: c4d.BaseObject | None  = c4d.BaseList2D(c4d.Ocube)
        if cube is None:
            return
        
        # The current interpolation offset based on #i.
        t: float = float(i) / float(CUBE_COUNT -1)

        # Set the size and position of the cube.
        cube[c4d.PRIM_CUBE_LEN] = CUBE_SIZE
        cube[c4d.ID_BASEOBJECT_REL_POSITION] = c4d.utils.MixVec(CUBE_POS_A, CUBE_POS_B, t)

        cube.InsertUnder(null)

    return null
</code></pre>
]]></description><link>http://developers.maxon.net/forum/post/72143</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/72143</guid><dc:creator><![CDATA[ferdinand]]></dc:creator><pubDate>Tue, 01 Aug 2023 13:10:06 GMT</pubDate></item></channel></rss>