paulmach / orb

Types and utilities for working with 2d geometry in Golang
MIT License
886 stars 103 forks source link

Polygon and line intersection coordinates #111

Open lozitskiys opened 1 year ago

lozitskiys commented 1 year ago

Hi!

I'd like to know, how to rewrite this example from go.geo readme to use orb library:

path := geo.NewPath()
path.Push(geo.NewPoint(0, 0))
path.Push(geo.NewPoint(1, 1))

line := geo.NewLine(geo.NewPoint(0, 1), geo.NewPoint(1, 0))

// intersects does a simpler check for yes/no
if path.Intersects(line) {
    // intersection will return the actual points and places on intersection
    points, segments := path.Intersection(line)

    for i, _ := range points {
        log.Printf("Intersection %d at %v with path segment %d", i, points[i], segments[i][0])
    }
}

In my case I assume path points as polygon coordinates. Thanks!