C++ C# 贝塞尔曲线

二阶贝塞尔曲线公式

三阶贝塞尔曲线公式

C++ 三维坐标点 二阶到N阶源码

cpp 复制代码
//二阶公式:
FVector BezierUtils::CalculateBezierPoint(float t, FVector startPoint, FVector controlPoint, FVector endPoint)
{
	 float t1 = (1 - t) * (1 - t);
	 float t2 = 2 * t * (1 - t);
	 float t3 = t * t;
	 return t1 * startPoint + t2 * controlPoint + t3 * endPoint;
}

// 三阶贝塞尔曲线
FVector BezierUtils::BezierCurve(Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, float t)
{
    Vector3 B = Vector3.zero;
    float t1 = (1 - t) * (1 - t) * (1 - t);
    float t2 = 3 * t * (1 - t) * (1 - t);
    float t3 = 3 * t * t * (1 - t);
    float t4 = t * t * t;
    return t1 * p0 + t2 * p1 + t3 * p2 + t4 * p3;
}
 
/// n阶贝塞尔曲线
FVector BezierUtils::BezierCurve(List<FVector3> pointList, float t)
{
    FVector B = FVector(0,0,0);
    if (pointList == null)
    {
        return B;
    }
    if (pointList.Count < 2)
    {
        return pointList[0];
    }
 
    List<Vector3> tempPointList = new List<Vector3>();
    for (int i = 0; i < pointList.Count - 1; i++)
    {
        Vector3 tempPoint = BezierCurve(pointList[i], pointList[i + 1], t);
        tempPointList.Add(tempPoint);
    }
    return BezierCurve(tempPointList, t);
}

C# 三维坐标点 二阶到N阶源码

cs 复制代码
using UnityEngine;
using System.Collections.Generic;
 
/// <summary>
/// 贝塞尔工具类
/// </summary>
public static class BezierUtils
{
    /// <summary>
    /// 线性贝塞尔曲线
    /// </summary>
    public static Vector3 BezierCurve(Vector3 p0, Vector3 p1, float t)
    {
        Vector3 B = Vector3.zero;
        B = (1 - t) * p0 + t * p1;
        return B;
    }
 
    /// <summary>
    /// 二阶贝塞尔曲线
    /// </summary>
    public static Vector3 BezierCurve(Vector3 p0, Vector3 p1, Vector3 p2, float t)
    {
        Vector3 B = Vector3.zero;
        float t1 = (1 - t) * (1 - t);
        float t2 = 2 * t * (1 - t);
        float t3 = t * t;
        B = t1 * p0 + t2 * p1 + t3 * p2;
        return B;
    }
 
    /// <summary>
    /// 三阶贝塞尔曲线
    /// </summary>
    public static Vector3 BezierCurve(Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, float t)
    {
        Vector3 B = Vector3.zero;
        float t1 = (1 - t) * (1 - t) * (1 - t);
        float t2 = 3 * t * (1 - t) * (1 - t);
        float t3 = 3 * t * t * (1 - t);
        float t4 = t * t * t;
        B = t1 * p0 + t2 * p1 + t3 * p2 + t4 * p3;
        return B;
    }
 
    /// <summary>
    /// n阶贝塞尔曲线
    /// </summary>
    public static Vector3 BezierCurve(List<Vector3> pointList, float t)
    {
        Vector3 B = Vector3.zero;
        if (pointList == null)
        {
            return B;
        }
        if (pointList.Count < 2)
        {
            return pointList[0];
        }
 
        List<Vector3> tempPointList = new List<Vector3>();
        for (int i = 0; i < pointList.Count - 1; i++)
        {
            Vector3 tempPoint = BezierCurve(pointList[i], pointList[i + 1], t);
            tempPointList.Add(tempPoint);
        }
        return BezierCurve(tempPointList, t);
    }
}
相关推荐
CyL_Cly2 小时前
杀戮尖塔2mod:二次元猎宝
windows·游戏
不做菜鸟的网工4 小时前
Windows WSL 使用技巧
windows
heimeiyingwang6 小时前
【架构实战】Event Sourcing事件溯源详解
windows·架构
少控科技7 小时前
小数典 - V1.0.0.1
windows·c#
遇见火星7 小时前
Firewalld 防火墙实战指南 + TCPWrapper 七层访问控制
开发语言·windows·python
eastyuxiao8 小时前
MMM 工具一键去水印+检测 批处理脚本(Windows/Mac 双版本)
人工智能·windows·macos·ai音乐去水印
Ching·8 小时前
MAC mini上面安装虚拟机windows11的安装详细过程及其问题解决
windows·macos·wmware fusion
Controller-Inversion8 小时前
207. 课程表
windows
longerxin202019 小时前
卸载 CCleaner 失败?用 Revo Uninstaller 彻底清干净(附官方下载 + 详细步骤)
windows
AC赳赳老秦1 天前
OpenClaw多平台部署:Windows+Linux跨系统协同,实现全场景覆盖
linux·服务器·前端·网络·windows·deepseek·openclaw