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);
    }
}
相关推荐
love530love16 小时前
【笔记】ComfyUI 启动时端口被占用(PermissionError [winerror 10013])解决方案
人工智能·windows·笔记·stable diffusion·aigc·端口·comfyui
Biehmltym16 小时前
【AI】02实现AI Agent全栈:十分钟,跑通Python调用 Gemini(大模型)的小型Web项目
人工智能·windows·python
无限进步_16 小时前
C++ Vector 全解析:从使用到深入理解
开发语言·c++·ide·windows·git·github·visual studio
Halo_tjn18 小时前
Java Set集合知识点
java·开发语言·数据结构·windows·算法
YJlio19 小时前
CSDN年度总结2025:技术逐梦不止,步履坚定向前
windows·学习·流程图
十五年专注C++开发19 小时前
QProcess在Windows下不能正常启动exe的原因分析
开发语言·c++·windows·qprocess·createprocess
无限进步_19 小时前
C++ STL容器适配器深度解析:stack、queue与priority_queue
开发语言·c++·ide·windows·算法·github·visual studio
新手村-小钻风19 小时前
Windows 环境下安装 Docker 的详细教程(超详细图文)
windows·docker·容器
无限进步_19 小时前
C++ STL list容器深度解析与模拟实现
开发语言·数据结构·c++·windows·git·list·visual studio
驱动开发0071 天前
Windows_Hello_Configuration_Analysis Windows Hello 配置过程分析 setup包分析
windows·驱动开发·云计算·计算机外设·usb重定向