Java Geometry Algorithm oneThirdPoint(@Nonnull Point2D pA, @Nonnull Point2D pB)

Here you can find the source of oneThirdPoint(@Nonnull Point2D pA, @Nonnull Point2D pB)

Description

calculate the point 1/3 of the way between two points

License

Open Source License

Parameter

Parameter Description
pA the first point
pB the second point

Return

the point one third of the way from pA to pB

Declaration

@CheckReturnValue
public static Point2D oneThirdPoint(@Nonnull Point2D pA, @Nonnull Point2D pB) 

Method Source Code

//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));
    }
}

Related

  1. mirrorMoveVertically(Point move, int size)
  2. nearestColinearPoint(final double x1, final double y1, final double x2, final double y2, double x, double y)
  3. nearestColinearPoint(final Line2D segment, final Point2D point)
  4. nearestPointOnLine(Line2D l, Point2D p, boolean clampToSegment, Point2D dest)
  5. newZeroPoint()
  6. parabolaByFocusAndDirectrix(Point2D.Double focus, double directrix)
  7. parameterizeCurve(Point[] coefficients, Point startPoint, Point endPoint, Point controlPoint1, Point controlPoint2)
  8. perpendicular(Point a, Point z, double aDist, double size, boolean clockwise)
  9. perpendicularScalarProjection(Point2D.Double projVec, Point2D.Double dir)