OberonPlace.com Forums

OberonPlace.com Forums (http://forum.oberonplace.com/index.php)
-   CorelDRAW/Corel DESIGNER VBA (http://forum.oberonplace.com/forumdisplay.php?f=16)
-   -   Drawing smooth curves (http://forum.oberonplace.com/showthread.php?t=24690)

nic 08-08-2014 21:34

Drawing smooth curves
Trying to draw hundreds of smooth curves from an Excel spreadsheet and struggling to find a way that doesnt require manual intervention.

I currently have a macro that reads in the node points (Excel only has the x,y coordinates) and draws overlapping curves - the first two/last three nodes overlap the previous/next curve. Each part of each curve is created with AppendLineSegment then the curve is created with CreateCurve. I can then manually select each curve/select All Nodes/To Curves/Smooth and use a macro to delete the first and last node, ending up with non-overlapping curves that look like a continuous smooth line.

I had tried to use AppendCurveSegment but whilst this created curved nodes with handles the lines were not smooth - I think because of the lack of control handle information and I would need to manually change the nodes back To Lines before converting them back To Curves.

The method wasnt good but I could get away with it with a few curves but now I want to draw hundreds of small curves of about 20 nodes each and Im wondering if someone could give advice about how to go about it.

Best wishes

nic 09-08-2014 17:04

Excel test file and code that fails
1 Attachment(s)
This is code that the code as it was when I gave up trying and attached small excel sheet that will work with it.

If theres a good place to look for Node info could somebody point me in the right direction.


Dim sShape As Shape
Dim crv As Curve
Dim sp As SubPath
Dim ro1st As Double
Dim roFin As Double
Dim x As Double, y As Double, r As Double, n As Double
Dim nd As Node

Set XL = GetObject(, "Excel.Application")

x = XL.Cells(1, 1).Value
y = XL.Cells(1, 2).Value

Set crv = CreateCurve(ActiveDocument)
Set sp = crv.CreateSubPath(x, y)

For n = 2 To 22
    x = XL.Cells(n, 1).Value
    y = XL.Cells(n, 2).Value
    sp.AppendCurveSegment x, y
Next n

sp.Closed = False

Set sShape = ActiveLayer.CreateCurve(crv)

' above draw a shape but below fails
For Each nd In sShape
    nd.Type = cdrSmoothNode
Next nd

End Sub

shelbym 11-08-2014 14:18


Change your below fails code to:

    ' above draw a shape but below fails
    For Each nd In sShape.Curve.Nodes
        nd.Type = cdrSmoothNode
    Next nd

See if that gives you the result you would like.

There are other ways of doing this also, you could draw an arc between three points, it would give you a smoother look with fewer nodes, if that is what you are looking for.


nic 11-08-2014 17:22

Thanks Shelby, that worked perfectly.

I shall look into the 3 point curves method and report back but Im thinking it wont do here and actually it has made me think I should overlap by another node .

Many thanks, really appreciate all the help you have given.

nic 24-09-2014 01:03

3 point curve
Hi Shelby
Had a look at drawing using the 3 point curve method and fell at the first hurdle because it seemed to require the bezier curve handle positions as part of its function and calculating those is beyond me. Im trying to draw mathematical curves a bit like spirographs from their x,y coordinates and the method that produced the smoothest if not the most accurate curves was to plot the whole curve (of up to 100000 nodes) in chunks of 2004 smooth nodes per shape and then deleting every other node and then the first and last nodes leaving a curve with 1000 nodes. By overlapping the next curve so its original 2004 node curve started at the penultimate node of the previous curve and deleting as before the 2nd curve started at the point the first curve finished and the curve between the two shapes flowed smoothly.
Best wishes

All times are GMT -5. The time now is 06:28.

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2022, Jelsoft Enterprises Ltd.
Copyright © 2011, Oberonplace.com