Python derivativeat

Read here for LOTS more of these


@ForestOwl, do you remember the thread you created about vector.unitize()
You’re making the same mistake here. :slight_smile:

shuffle will modify the list and not create another one.
so not print a but rather print thing

1 Like


Can this,
be somehow fixed with the Rhino embedded python engine?
I can imagine huge problems can emerge if the coder is careless. :crazy_face:

1 Like

Just tried this in CPython 2.7:

True = False
True == False


True = not False
True == False


Yes, I read that since at the beginning there were no booleans in python in order to make them backportable they derived True and False from the int() class.

This made them mutable in all Python2 versions. Which was also transferred to IronPython.

I assumed since the C# connection they might have fixed that but unfortunately they didn’t. Perhaps this could be fixed somehow with the embedded engine bind it somehow to .net’s booleans. I don’t know. I’m not familiar with low level programming.

I’m not going to change this behavior.


And I think the Ironpython dev will focus on trying to finish 3.4 before he tries to ´fix’ 2.7

1 Like

I tried PointAt this time too, but it seems I am doing something wrong.
I have the curve length of 84, then I have a list of numbers between 0 and 84.

When I use PointAt, my points fly everywhere. Do you might know why?

problem derivativeat (20.6 KB)

I find your code difficult to follow. It is good practice if you don’t use good descriptive names for the variables to place comments explaining what you’re trying to do.

Up to the part where you remove the duplate values from the list and you sort it everything is clear, but after that I really don’t get what you’re trying to do.

Thank you for saying, I changed it.

I hope it is more clear now.

I have a curve and I want to place points on it between 0 and the MAX length of the curve.
I made values and somehow by using PointAt, the points fly away. I do not yet understand why. Do you might know why my points are not on that curve?

problem derivativeat (27.0 KB)

The parameter values you are randomly generating are outside the domain of the curve:

1 Like


Point at takes parameter not distance on the curve

1 Like

One of the components here does what you want.

It will be a good test to see if it works with multiple length values instead of the slider. I do not remember how I intended it to work :smiley:

I can fix it.

1 Like

I need python, does it not exist in python?

@ivelin.peychev @ivelin.peychev
Does one of you might know which places the points by length?

EDIT: never mind, I found it from a former post
Curve.PointAtLength Method

You’ll have to normalize the length if I remember correctly, keep that in mind

1 Like

No it seems it can be used without normalizing the length.

1 Like

Great! :slight_smile:

You could also, you know, look up the documentation:

1 Like

I guess my component seems to work without a slider :slight_smile:

You’re logic is wrong, @ForestOwl! You need to remap your desired distance for each curve from the curve length domain to the curve domain.

Let’s say your desired, random distance for a point on the curve is 2.5, and the domain of the curve is (3.5, 5.0), whereas its length domain is (0.0, 84.856). At the moment, you try to create a point at the curve parameter 2.5, which doesn’t exist. This makes your point appear somewhere else.
Instead, you simply remap your distance to the curve domain. For this example, that should be a curve parameter of 3.544… that fits on your curve, since it’s included in the curve domain!

import Rhino.Geometry as rg
import random


def fit(value, source_domain, target_domain):
    """Fits a number between a target domain that is relative to a number in the source domain.
        value: number to be fitted
        source_domain: tuple containing the domain start and end
        target_domain: tuple containing the domain start and end
        The refitted value, or None, if the initial value is outside the source domain.
    if (value < source_domain[0]) or (value > source_domain[1]):
        source_range = source_domain[1] - source_domain[0]
        if source_range == 0:
            fitted_value = target_domain[0]
            target_range = target_domain[1] - target_domain[0]
            fitted_value = (((value - source_domain[0]) * target_range) / source_range) + target_domain[0]
        return fitted_value

curr_plane = Planes[0]
curr_crv = Curves[0]
min_dist, max_dist = DistInterval

# Get the curve length
crv_len = curr_crv.GetLength()
# Get the curve domain
crv_dom = curr_crv.Domain

curr_dist = 0.0 # current desired distance
crv_parameters = [] # curve parameters
div_pts = [] # curve division points

while curr_dist < crv_len:
    # Remap the desired distance to the curve domain
    crv_param = fit(curr_dist, (0.0, crv_len), crv_dom)
    # Check if curve parameter hasn't been visited yet
    if crv_param not in crv_parameters:
        # Get the curve point for the curve parameter
        pt = curr_crv.PointAt(crv_param)
        # Add the curve point to the division points list
        # Add the curve parameter to the curve parameters list as history entry
    # Randomly increment the current desired distance
    curr_dist += random.randint(min_dist, max_dist)

a = div_pts

problem derivativeat (16.4 KB)

No, this wouldn’t work either! When normalising the curve domain or curve length, you still have to remap your distance to the normalised domain, when it’s not between 0.0 and 1.0.