ichigo/geom/cmd/splinetester.go

56 lines
1.2 KiB
Go
Raw Normal View History

2021-10-03 15:50:09 +11:00
//go:build example
// +build example
2021-10-05 10:16:17 +11:00
/*
Copyright 2021 Josh Deprez
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
2021-10-03 15:50:09 +11:00
package main
import (
"fmt"
"log"
"github.com/DrJosh9000/ichigo/geom"
)
func main() {
// Put your own points here!
points := []geom.Float2{
{X: -7, Y: -2},
{X: -5, Y: 1},
{X: -3, Y: 0},
{X: -2, Y: -3},
{X: 0, Y: 2},
{X: 1, Y: -5},
{X: 3, Y: -2},
{X: 4, Y: 4},
}
2021-10-04 13:33:35 +11:00
cubic := &geom.CubicSpline{
Points: points,
2021-10-04 12:32:05 +11:00
FixedPreslope: true,
2021-10-04 13:33:35 +11:00
FixedPostslope: true,
2021-10-04 12:32:05 +11:00
Preslope: -5,
2021-10-04 13:33:35 +11:00
Postslope: -4,
2021-10-04 12:32:05 +11:00
}
2021-10-03 15:50:09 +11:00
if err := cubic.Prepare(); err != nil {
log.Fatalf("cubic.Prepare() = %v, want nil", err)
}
// Produce interpolated points in CSV-like form.
2021-10-04 12:32:05 +11:00
for x := -8.0; x < 8.0; x += 0.0625 {
2021-10-04 13:33:35 +11:00
fmt.Printf("%f,%f\n", x, cubic.Interpolate(x))
2021-10-03 15:50:09 +11:00
}
}