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);
    }
}
相关推荐
JOJO___19 小时前
【2026】记录在windows编译llama.cpp步骤,AMD CPU本地部署千问3.5本地大模型,内存占用低
windows·cpu·amd·llama.cpp·llama.cpp编译·千问3.5·本地大语言模型
神奇椰子20 小时前
Windows 系统 MC 服务器搭建保姆级教程
运维·服务器·windows
csdn小瓯21 小时前
Pydantic V2 模型校验与配置管理最佳实践
运维·数据库·windows
元Y亨H21 小时前
彻底掌控你的电脑:Windows 自动更新关闭全攻略
windows
芊&星21 小时前
靶机应急 | 知攻善防----Windows
运维·windows·安全
likerhood1 天前
Java final 关键字:从“不能改”到“安全发布”的深入理解
java·windows·安全
clear sky .1 天前
[freeRTOS源码阅读]list.c/h
linux·服务器·windows
星间都市山脉1 天前
Windows 环境 Android 系统 APK 签名操作文档
android·windows
薛定猫AI1 天前
Codex 与 Claude Code 全平台安装配置指南(Windows / macOS / Linux)
linux·windows·macos
console.log('npc')1 天前
Windows 11 安装 WSL2 + Ubuntu + Docker + Codex + Sub2API 教学
windows·docker·powershell·ubantu·codex