CV Curve curvature not matching the manual drawn

CV Curve curvature not matching the manual drawn

victorEFVH7
Enthusiast Enthusiast
918 Views
6 Replies
Message 1 of 7

CV Curve curvature not matching the manual drawn

victorEFVH7
Enthusiast
Enthusiast

Hi,

 

Im trying to do a CV Curve to match a nurbs curve based on points position.

 

In the attached image and maxfile (2020) I have three different curves, 

Green illustrates the position of each point / vert.

Orange illustrates if I draw a CV Curve in the viewport by clicking on each vert on the green spline 

Blue is if I create a CV Curve through maxscript based on the verts position of the green spline.

 

Orange is the correct representation but I can't achieve it with maxscript, the weight gets completely off.

 

How can I achieve the same weight as the manually drawn CV Curve?

 

Example code with the points position of the green spline.

   rpt = #([-0.907021,0.0867096,0],
	[-0.176184,0.50787,0],
	[0.474138,0.0309677,0],
	[1.68188,0.29729,0],
	[2.44368,-0.266322,0],
	[0.820976,-1.20155,0])
   
   
   nset = NURBSSet ()
   -- create a new NURBSCVCurve and set the knots and CVs
   c = NURBSCVCurve name:"CV Curve" order:rpt.count numCVs:rpt.count numKnots:(rpt.count*2)
   for k in 1 to rpt.count do ( setKnot c k 0; setKnot c (k+rpt.count) 1 )
   cv = NURBSControlVertex rpt[1]
   setCV c 1 cv
	for i= 2 to rpt.count do (

   cv.pos = rpt[i]
   setCV c i cv

	)
   -- add the NURBSCVCurve object to the set
   appendObject nset c
   -- create the NURBS object from the NURBSSet
   n = NURBSNode nset name:"nurbs01"a

 

 

0 Likes
919 Views
6 Replies
Replies (6)
Message 2 of 7

leeminardi
Mentor
Mentor

You created a degree 3 NURBS manually while your script created a degree 5 NURBS from the same list of CVs.

 

Some time ago, to better undertsand B-splines and NURBS I wrote a custom B-spline function in VBA/Excel.   If the weights of the CVs in a NURBS are all equal to 1 then it can be considered a B-spline.  The attached VBA Macro enabled Excel file shows the shape of your spline if it is a degree 5 spline.  Change the 5 to a 3 and you get your manually drawn spline.

leeminardi_0-1709001536712.png

 

lee.minardi
0 Likes
Message 3 of 7

victorEFVH7
Enthusiast
Enthusiast
Sorry for late reply @leemindari Thanks for bringing some clarity.
So you mean that I need to calculate the weight for each point to get a correct representation or the curve
When creating it through maxscript?

Or how should I adjust it to represent a 3 degree spline?
0 Likes
Message 4 of 7

leeminardi
Mentor
Mentor

@victorEFVH7  Short answer, I d  not know how to set the degree of the splne. The CV weights are not the problem. They all should be and are 1. The challenge is setting the degree to 3 before the creation of the spline. 

As noted here, the order of a spline is one more than the degree of the spline.  It is also states that " CV curves and surfaces must obey the relationship that "order + number of CVs = number of knots". If this is not the case in most cases no object will be created and in some cases an assertion fault might be generated."  YOur code has the correct relationship between these 3 properties.

 

I tried changing the order to 4, and knots to 10 with no success.

lee.minardi
0 Likes
Message 5 of 7

Swordslayer
Advisor
Advisor

You'd have to know how the knot values are distributed. This is with uniform distribution which creates valid degree 3 (what you have) NURBS curve but not the same shape:

 

nset = NURBSSet()
c = NURBSCVCurve name:"CV Curve" order:3 numCVs:rpt.count numKnots:(rpt.count + 3)

for i = 1 to rpt.count do setCV c i (NURBSControlVertex rpt[i])
for k = 1 to c.numKnots do setKnot c k (k as double / c.numKnots)

appendObject nset c
NURBSNode nset prefix:"NurbsCurve" isSelected:on
0 Likes
Message 6 of 7

Swordslayer
Advisor
Advisor

Scratch that, just realized order is degree + 1, not just degree. So this gets closer but still not completely sure how to arrive at the correct knot values:

 

 

	degree = 3
	nset = NURBSSet()
	c = NURBSCVCurve name:"CV Curve" order:(degree + 1) numCVs:rpt.count numKnots:(rpt.count + degree + 1)

	for i = 1 to rpt.count do setCV c i (NURBSControlVertex rpt[i])

	for k = 1 to c.order do setKnot c k 0
	for k = c.order + 1 to c.numKnots - c.order do
		setKnot c k ((k - c.order as double) / (c.numKnots - degree))
	for k = c.numKnots - c.order + 1 to c.numKnots do setKnot c k 1

	appendObject nset c
	NURBSNode nset prefix:"NurbsCurve" isSelected:on wirecolor:yellow

 

0 Likes
Message 7 of 7

victorEFVH7
Enthusiast
Enthusiast

Thanks guys this seam to solve the problem with an additional setting,

if you select the object. Head over to the dropdown in modifier stack and select curve under cv curve , then go down to automatic reparam and set it to uniform then ut matches the curve correctly.

https://help.autodesk.com/view/MAXDEV/2022/ENU/?guid=GUID-593123B8-0F17-4944-861E-57C9458BF61E

However I cant manage to set it through maxscript. It doesnt do anything if I 

c = NURBSCVCurve name:"CV Curve" order:(degree + 1) numCVs:rpt.count numKnots:(rpt.count + degree + 1) autoParam: #autoUniform

But it works when setting it manually in the modifier stack?

 

I have a different question while we are on it, lets say that we have the knot vector of this NURBS curve, how can I set these accordingly to these values?

 

 

rpt_knot = #(0.0,
0.0,
0.0,
19.024189488806,
38.048378977612,
57.072568466418005)

 

for i = 1 to rpt_knot.count do setKnot c i rpt_knot[i] doent work.

 

0 Likes