Here you can find the source of oneThirdPoint(@Nonnull Point2D pA, @Nonnull Point2D pB)
Parameter | Description |
---|---|
pA | the first point |
pB | the second point |
@CheckReturnValue public static Point2D oneThirdPoint(@Nonnull Point2D pA, @Nonnull Point2D pB)
//package com.java2s; //License from project: Open Source License import java.awt.geom.Point2D; import javax.annotation.CheckReturnValue; import javax.annotation.Nonnull; public class Main { /**//from www . j av a2s . c o m * calculate the point 1/3 of the way between two points * * @param pA the first point * @param pB the second point * @return the point one third of the way from pA to pB */ @CheckReturnValue public static Point2D oneThirdPoint(@Nonnull Point2D pA, @Nonnull Point2D pB) { return lerp(pA, pB, 1.0 / 3.0); } /** * calculate the linear interpolation between two integers * * @param a the first number * @param b the second number * @param t the fraction (between 0 and 1) * @return the linear interpolation between a and b for t */ @CheckReturnValue public static int lerp(int a, int b, double t) { return (int) lerp((double) a, (double) b, t); } /** * calculate the linear interpolation between two doubles * * @param a the first number * @param b the second number * @param t the fraction (between 0 and 1) * @return the linear interpolation between a and b for t */ @CheckReturnValue public static double lerp(double a, double b, double t) { return ((1.0 - t) * a) + (t * b); } /** * calculate the linear interpolation between two Doubles * * @param a the first number * @param b the second number * @param t the fraction (between 0 and 1) * @return the linear interpolation between a and b for t */ @CheckReturnValue public static Double lerp(@Nonnull Double a, @Nonnull Double b, @Nonnull Double t) { return ((1.0 - t) * a) + (t * b); } /** * calculate the linear interpolation between two points * * @param pA the first point * @param pB the second point * @param t the fraction (between 0 and 1) * @return the linear interpolation between a and b for t */ @CheckReturnValue public static Point2D lerp(@Nonnull Point2D pA, @Nonnull Point2D pB, double t) { return new Point2D.Double(lerp(pA.getX(), pB.getX(), t), lerp(pA.getY(), pB.getY(), t)); } }