GHPython: Setting the weight of a surface control point changes the location of the point

I don’t understand why the SetPoint() or SetWeight() methods change the points location when I set the weight to a different value from the default 1.0.
It seems like the higher the weight set, the closer the control point moves towards the origin.
How do you change a control point’s weight without moving its location?

Weight Set at 1.0 with control point in correct location:

Weight Set at 1.3 with control point moving towards origin?!

Here is the code:

import Rhino.Geometry as rg

#Define Function To Move A Control Point
def Move_Point(Control_Points_List, U, V, X, Y, Z, Weight):

#Select Point at U,V Index 0,0
Control_Point = Control_Points_List.GetControlPoint(U,V)

#Move Point X, Y, Z
Control_Point.X += X
Control_Point.Y += Y
Control_Point.Z += Z

Control_Point.Weight = Weight

#Set Control Point
Control_Points_List.SetControlPoint(U,V,(Control_Point))

Move_Point(Control_Points, 1, 1, 0, 0, 5, Weight_In)

I think I have understood the issue. And it definitely explains why the points were moving toward the origin.
The Set Control Point seems to behave like this:

ControlPoint(Point4d)Constructs a new homogeneous control point, where the 4-D representation is (x, y, z, w). The world 3-D, or Euclidean, representation is (x/w, y/w, z/w).

From: https://developer.rhino3d.com/api/RhinoCommon/html/T_Rhino_Geometry_ControlPoint.htm

The solution is to multiply the X, Y, Z positions by the new weight set. Seems very odd that the point is represented this way but it works now…

Here is the code:

import Rhino.Geometry as rg

def Move_Point(Control_Points_List, U, V, X, Y, Z, Weight):

#Select Point at U,V Index 0,0
Control_Point = Control_Points_List.GetControlPoint(U,V)

#Set The New Weight
Control_Point.Weight = Weight

#Move Point X, Y, Z & Compensate For The Weight (X/W -> X*W)
Control_Point.X = (Control_Point.X + X) * Weight
Control_Point.Y = (Control_Point.Y + Y) * Weight
Control_Point.Z = (Control_Point.Z + Z) * Weight

#Set Control Point
Control_Points_List.SetControlPoint(U,V,(Control_Point))

Move_Point(Control_Points, 1, 1, 0, 0, 3, Weight)

1 Like