NURBS (freedom) line coordinate

Started by korash, April 18, 2011, 10:15:20 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

How to get NURBS (freedom) line's X & Y coordinate?

NURBS
1 (100%)
SPLINE
0 (0%)

Total Members Voted: 1

korash

I need to extract the X,Y coordinates of knots of NURBS. I know that NURBS formula includes relative X and Y coordinates. But those knots are different from the dots on the spline which we can see when we click the spline to edit. Non-Uniform Rational B-Spline's knots which are control points in Visio are not visible at all. But we can see the different control points as dots. But there is no way that we can retrieve those control points' coordinates directly. Anyone who knows how to actually get those control points X,Y coordinates?

Visio Guy

Hi korash,

I'm curious why you want to know where the handles are?

I don't know of anyway to get the coordinates. I know you can parse the NURBS function to get mathematical info, but as you say, I guess the x-y data isn't the same as the location of the handles.
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

JuneTheSecond

#2
Paths property of shape may extract X,Y coordinates of knots of NURBS.
If a page has only one shape that has only one NURB spline, next macro might do.


Public Sub Paths_Example()

    Dim vsoShape As Visio.Shape
    Dim adblXYPoints() As Double
    Dim intOuterLoopCounter As Integer
    Dim intInnerLoopCounter As Integer
    Set vsoShape = ActivePage.Shapes(1)

    For intOuterLoopCounter = 1 To vsoShape.Paths.Count

        vsoShape.Paths(intOuterLoopCounter).Points 1#, adblXYPoints
        For intInnerLoopCounter = LBound(adblXYPoints) To UBound(adblXYPoints) Step 2
            Debug.Print adblXYPoints(intInnerLoopCounter), adblXYPoints(intInnerLoopCounter + 1)
        Next intInnerLoopCounter

    Next intOuterLoopCounter

End Sub


   
Best Regards,

Junichi Yoda
http://june.minibird.jp/

cliff50

I tried this to target the E cell in a line squiggle.
is this the data for the knots ??

Public Sub NurbEcellvalues()
Dim shp As shape
Set page = Visio.ActivePage


For Each shape In page.Shapes
    Set shp = shape

    Debug.Print shp.Cells("Geometry1.E2").Formula


Next shape

End Sub

cliff50

output of that macro was:

NURBS(3.1443073372887, 3, 0, 0, 0.0037035369801234,0.46401140608623,0,1, 0.14263217597699,0.8431281694405,0,1, 0.38306470636767,1.1367357700397,0,1, 0.10703737316977,-0.32772633555689,0.54239597892079,1, 0.3939660988976,0.23864683589884,0.59596114142262,1, 0.52648439392208,0.042808834023508,1.1376729906531,1, 0.77178901425333,0.39185069986971,1.2844586705359,1, 0.77705037616107,0.85196286137017,1.5035918554734,1, 0.865684592908,1.0804937234079,2.2319853326777,1, 0.98972421949493,0.43304440543709,2.5368855432435,1)


korash

Hi, Visio Guy

The reason I need to know the coordinates of handle points is that I need to use 3D animation application which determine the object path using Kochanek-Bartels Tension-Continuity-Bias (KBTBC) Splines. This KBTCB spline's control points(knots) are located on the path. The user of this 3D animation application need to define the Paths using KBTBC spline specifying the handle points as X,Y coordinates. For example, "PATH SPLINE '(104,100)' '(298,284)' '(234,202)". This syntax will create the path in that application having 3 control points on those given coordinates. The elevation coordinates are determined by the terrain elevation. This 3D animation doesn't have the drawing tool which user can draw and see the path in Virtual world within the application.

So I just thought that I can use Visio 2007 to draw the path using freedom line onto the satellite image of terrain because in Visio, I can simply export the simple lines' BeginX,Y & EndX,Y using VBA. And I knew about NURBS which is a formula of MS Visio's spline. As cliff50 posted as a reply of my post, we can simply know that NURBS function which MS is using to create the Non-Uniform Rational B-Spline. But y coordinates of all knots are not representing the handle points we can see from the Visio as a modeler or a user. For instance from the cliff50's NURBS formula example,

1) 0.14263217597699:x2, 0.8431281694405: y2
2) 0.38306470636767:x3, 1.1367357700397: y3
3) 0.10703737316977:x4, -0.32772633555689: y4

Those 3 points are three knots' x & y local coordinates. Let's assume that the Width and Height of the spline object are all 100 then. And also we need to assume that angle is zero.

Then, the 2nd knots points will be at 100x0.14263217597699=14.26 as X coordinate, and 100x0.8431281694405=84.31 as Y coordinate. But the handle points which allows user to edit the shape of spline are not located on those points. Simply because the knots are not the points the user can see as visual dots in Visio. X coordinates are correct but Y coordinates are the actual handle points. If you can see the attached file as an example, you can understand this matter clearly.

The attached image's spline formula is NURBS(21.4526, 3, 0, 0, 0.0664,0.1823,0,1, 0.2407,-0.119,0,1, 0.4765,0.1284,0,1, 0.5893,1.4129,5.4341,1, 0.9259,0.7905,9.6657,1). The red line is spline and the blue lines are connecting the knots calculated from the given formula. And the parameter description of the attached file is explained in detail below.

21.4526: knotLast
3: degree
0: xType
0: yType
0.0664: x1
0.1823: y1
0: knot1
1: weight1
0.2407: x2
-0.119: y2
0: knot2
1: weight2
0.4765: x3
0.1284: y3
0: knot3
1: weight3
0.5893: x4
1.4129: y4
5.4341: knot4
1: weight4
0.9259: x5
0.7905: y5
9.6657: knot5
1: weight5

The green box is created based upon Height, and Width. But as you can see from y2, and y4, these two points are out of bound box which you can see from the blue line from the attached file. This is true based upon my understanding of Non-Uniform Rational B-Spline algorithms. But these knots are not visible to users but the green dots as handle points which user use to manipulate and edit the shape of spline are visible. And I would like to know those green dots coordinates!! I know that I can do this from creating basis function of NURBS from the given formula and re-create the fusion function then input the x-coordinates of knots then the calculated functions can give us Y-coordinates of those green dots. But this takes a lot of efforts. And in my common sense, this doesn't make any sense because we can see those green dots but we cannot know the coordinates of those points?
Please help me out this matter. There must some function which I can use to retrieve those coordinates easily.

And about the JuneTheSecond posting...
I knew that Path function. But the problem of that function is that path function gives us coordinates of points along the spline which are divided by given precision from user. Those divided points doesn't point out where the handle points are. What the function does is that dividing a spline into 10 or 100 or 1000 segments as user specifies, then store those equally spaced points coordinates into array. So this doesn't solve my problem.

cliff50

Hi Korash,
regard your explaination of the NURB parameters:

21.4526: knotLast
3: degree
0: xType
0: yType
0.0664: x1
0.1823: y1
0: knot1
1: weight1

In your mind, what does the "degree" value actually mean ? 
I ask because I often see the value 3 appearing in this position  of the nurb function in the shapesheet.

also, I am not so sure if the X co-ordinate values of the handles coincide with the X co-ordinate values of the NURB formula, in your diagram red\blue the blue dots don't seen to align with the green dots on the X axis.

I agree with your other observations.

If what your say is correct, then a perfect sine wave should be able to be created with just two green dots ( the intermediate handles), and the terminating handles at the start and end points of the spline. Furthermore this perfect sine wave should be able to be created by manually manipulating the shapesheet formula values of the NURB E cell.

korash

Thanks cliff50 for you reply.

The degree 3 means that the basis function is polynomial function degree of 3.

And I will try to answer to the X-coordinate problem later. That is a kind of rotation problem maybe.

Spline's basis functions have nothing to do with Sine Curve.

cliff50

Korash, sorry I meant  a perfect sinusoidal wave of only one wavelength, may be mimmicked by a cubic function (3 degree polynomial) e.g Y = x^3 -X= (X-1)X(X+1).(within the length of one wavelegth)  is the same shape (in part) as Y = A sine(angle).(one wavelength only)

The problem I am having with the green knots is (and I guess you may already have found this) is the parameters values I enter into the NURB  function at the x1, y1 position from your explaination of the NURB inputs, I can alter the position of the green knots in both X and Y directions, but they do not reposition to where I expect them to be. I think I need to experiment more before I may suggest a definition of how the NURB algorithum works