All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.ru.casperix.math.curve.float64.LazyCurve2d.kt Maven / Gradle / Ivy

There is a newer version: 1.9.0
Show newest version
package ru.casperix.math.curve.float64

import ru.casperix.math.vector.float64.Vector2d

abstract class LazyCurve2d : Curve2d {
    override fun getTangent(t: Double): Vector2d {
        val smallValue = 0.0001
        if (t <= smallValue) {
            return (getPosition(t + smallValue) - getPosition(t)).normalize()
        } else if (t >= 1f - smallValue) {
            return (getPosition(t) - getPosition(t - smallValue)).normalize()
        } else {
            return (getPosition(t + smallValue) - getPosition(t - smallValue)).normalize()
        }
    }

    override fun invert(): Curve2d {
        TODO()
    }

    override fun getProjection(position: Vector2d): Double {
        return (0..10).map {
            val t = it / 10.0
            Pair(t, getPosition(t).distTo(position))
        }.minByOrNull { (_, dist)-> dist }!!.first
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy