Here’s an updated solution!

It should now do what you described above. If one or both distance values exceed the distance between the end points, the input distances get remapped to fit within the limits, and only two segments are produced.

```
"""Divides the distance between a start and end point into a desired number of
segments. The distance between the first two segments corresponds to the
desired distance values, whereas the remaining distance is divided equally.
If one or both desired distances exceed the distance between both points,
both distances get remapped to fit the limits.
Inputs:
StartPoint: Start point
EndPoint: End point
Count: Number of segments
Dist1: Distance of the first segment
Dist2: Distance of the second segment
Output:
Points: Division points"""
ghenv.Component.Name = "PythonicCustomDivide"
ghenv.Component.NickName = "CustomDivide"
__author__ = "p1r4t3b0y"
__email__ = "p1r4t3b0y@gmail.com"
__version__ = "1.0"
import Rhino.Geometry as rg
def fit(value, source_min, source_max, target_min, target_max):
"""Fits a value into new numeric domain.
Args:
value (int, float): A value to remap.
source_min: A start value of the source domain.
source_max: An end value of the source domain.
target_min: A start value of the target domain.
target_max: An end value of the target domain.
Returns:
The remapped value.
"""
source_range = source_max - source_min
if source_range == 0:
new_value = target_min
else:
target_range = target_max - target_min
new_value = (((value - source_min) * target_range) / \
source_range) + target_min
return new_value
# Get the directional vector
dir = EndPoint - StartPoint
# Get the maximum distance between the start and end point
max_dist = dir.Length
# Calculate the rest length
rest_len = max_dist - (Dist1 + Dist2)
# Unitize the directional vector to length 1
dir.Unitize()
div_pts = [] # divison points
# Get the division points
if rest_len >= 0: # rest length supports at least the first two divisions
# Calculate the division length beyond the second divison
div_len = rest_len / (Count - 2)
init_dists = [Dist1, Dist2] # initial distances
trav_dist = 0.0 # already travelled distance
for i in xrange(Count+1):
if i == 0: # the start point is the first division point
div_pts.append(StartPoint)
else: # other division points
# Process the desired first and second division points first
if len(init_dists) > 0:
trav_dist += init_dists[0]
next_pt = StartPoint + dir * trav_dist
div_pts.append(next_pt)
del init_dists[0]
# Process the remaining divisions
else:
# The following two lines are optional!
if rest_len == 0.0: # no rest length to divide
break # don't produce points
trav_dist += div_len
next_pt = StartPoint + dir * trav_dist
div_pts.append(next_pt)
else: # rest length does not supports even the first two divisions
# Remap the desired distances to fit between 0.0 and the maximum distance
d1 = fit(Dist1, 0.0, max([Dist1, Dist2]), 0.0, max_dist)
d2 = fit(Dist2, 0.0, max([Dist1, Dist2]), 0.0, max_dist)
min_d, max_d = sorted([d1, d2])
init_dists = [min_d, max_d - min_d] # initial distances
trav_dist = 0.0 # already travelled distance
print init_dists
for i in xrange(3):
if i == 0: # the start point is the first division point
div_pts.append(StartPoint)
else: # other division points
# Process only the remapped first and second division points
if len(init_dists) > 0:
trav_dist += init_dists[0]
next_pt = StartPoint + dir * trav_dist
div_pts.append(next_pt)
del init_dists[0]
# Outputs
Points = div_pts
```

GHPython_18.Dec.2019.gh (17.9 KB)