| Article | 70002914 |
| Type | HowTo |
| Product | Engine |
| Date Added | 9/9/2026 12:00:00 AM |
| Fixed | 12.1.1 (9/9/2026 12:00:00 AM) |
| Submitted by | Finn Lassen |
Summary
How to get Y value from X or X from Y with a Polyline
Solution
Using intersect functionality (IntersectWith method) you can get what you want. Note that the polyline must be a 2D polyline!
So try a code like:
vdPolyline poly = new vdPolyline(doc,new gPoints(new gPoint[] {new gPoint(0,0),new gPoint(1,0), new gPoint(1,1),new gPoint(0,1) }));
//getYfronX (x = 0.5)
vdLine line = new vdLine(doc,new gPoint(0.5, 0), new gPoint(0.5, 1));
gPoints intpts = new gPoints();
bool suc = poly.IntersectWith(line, VdConstInters.VdIntExtendArg, intpts);
if(suc && intpts.Count > 0)
{
//you can sort the intpts by x or y if you want to get the leftmost or rightmost intersection point
//see gpoints.SortByX() or gpoints.SortByY()
//gPoints.Sort -Or- gPoints.shortByPointOrigin
double y = intpts[0].y;
}
//getXfronY (y = 0.5)
line = new vdLine(doc, new gPoint(0, 0.5), new gPoint(1, 0.5));
intpts = new gPoints();
suc = poly.IntersectWith(line, VdConstInters.VdIntExtendArg, intpts);
if (suc && intpts.Count > 0)
{
//add your sorting here if you want to get the topmost or bottom most intersection point
double x = intpts[0].x;
}
