# Get from

### Highlights from jdugge/xy2sn

• sn2xy( s, n, centerlinex,...
sn2xy: Transform curvilinear orthogonal to cartesian coordinates
• xy2sn( x, y, centerlinex,...
XY2SN: Transform cartesian to curvilinear orthogonal coordinates
• View all files
4.0
4.0 | 1 rating Rate this file 15 Downloads (last 30 days) File Size: 141 KB File ID: #39796 Version: 1.3

# jdugge/xy2sn

### Juernjakob Dugge (view profile)

10 Jan 2013 (Updated )

Transform cartesian to curvilinear orthogonal coordinates, e.g. a flow-oriented coordinate system.

File Information
Description

Matlab functions to transform between cartesian (xy) and curvilinear orthogonal (sn) coordinates using a spline representation of a centerline.

Acknowledgements

Distance2curve, Arclength, and Interparc inspired this file.

Required Products MATLAB
MATLAB release MATLAB 8.0 (R2012b)
26 Jul 2015 Juernjakob Dugge

### Juernjakob Dugge (view profile)

Chad, thanks for your feedback, and apologies for my very delayed response. I've updated the submission to now use the absolute length along the centerline for the s-coordinate.

Comment only
26 Jul 2015 Juernjakob Dugge

### Juernjakob Dugge (view profile)

Brian, I don't know how this compares to CRG, sorry. If you can provide some detail on how that project converts between Cartesian and curvilinear coordinates, I might be able to comment.

Comment only
17 Jul 2015 Brian Liswell

### Brian Liswell (view profile)

How does this compare to curved regular grid (CRG) work being done for vehicle/road/terrain data?

https://en.wikipedia.org/wiki/OpenCRG

Comment only
08 Sep 2014 Matt Wolinsky

### Matt Wolinsky (view profile)

Nice submission overall.
A warning though: the spline interpolant is not necessarily monotone, particularly at the end-points. As a result, in my tests it was common to get major discontinuities in "Nsign" at the boundaries.
You might consider adding a pchip() option to avoid this (pchip is guaranteed monotone).

Comment only

These functions have proven quite helpful for me, Juernjakob! I would make one change: For most applications, the normalized s is awkward and unintuitive. For river flow applications it makes little sense to describe data points as being one-half of one river unit downstream. If data start out in meters, why not keep the data in meters? In every case I've needed to follow xy2sn with distanceAlongFlow=S*L. Then I often think I'm done with the L variable, only to realize that I should have kept it to transform back into the xy coordinate system.

In this situation, I have tried the following incorrect way of getting back to x,y:

[x,y] = sn2xy(distanceAlongFlow/max(distanceAlongFlow),N,centerlineX,centerlineY);

The above solution would only be correct if the maximum value in distanceAlongFlow is located at the endpoint of the centerline. If you find yourself in a similar situation, the correct solution can be obtained by

[x,y] = sn2xy(distanceAlongFlow/arclength(centerlineX,centerlineY,'sp'),N,centerlineX,centerlineY);

Despite this minor issue, the functions are quite useful--thanks for sharing.

Comment only
17 Dec 2013 Juernjakob Dugge

### Juernjakob Dugge (view profile)

Thanks for the feedback, Jie. I've edited the function to now use a linear approximation of the smoothed pathline, which speeds up the process significantly.

Comment only
12 Dec 2013 Jie

### Jie (view profile)

Hi, Juernjakob, this program is very useful for handling river data. The problem is that the efficiency of this program need to be improved. I tried it for just 150,000 points, and it is not finished for more than half an hour. You know, for most of field applications, data sets with more than one million data points is very common. So, it will be more useful, if the efficiency of this program could be improved in future.

27 Feb 2013 1.1

Added check for a bug in "distance2curve.m"

17 Dec 2013 1.2

Dramatically increased performance by using a piecewise linear approximation for the smoothed centerline.

17 Aug 2015 1.3

The s-coordinate is no longer normalised, but uses distance units. This is consistent with Merwade's description of the method. (Thanks to Chad Greene for raising this issue)