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);
    }
}
相关推荐
程序设计实验室2 小时前
在Windows上将git与ssh-agent搭配使用,再也不用输入git密码了
windows·git
海天胜景14 小时前
编译器错误消息: CS0016: 未能写入输出文件“c:\Windows\Microsoft.NET... 拒绝访问
c语言·windows
搏博1 天前
基于Python3.10.6与jieba库的中文分词模型接口在Windows Server 2022上的实现与部署教程
windows·python·自然语言处理·flask·中文分词
有梦想的攻城狮1 天前
Java 11中的Collections类详解
java·windows·python·java11·collections
忒可君1 天前
C# winform FTP功能
开发语言·windows·c#
十五年专注C++开发1 天前
CMake进阶: CMake Modules---简化CMake配置的利器
linux·c++·windows·cmake·自动化构建
degree5201 天前
全平台轻量浏览器推荐|支持Win/macOS/Linux,极速加载+隐私保护+扩展插件,告别广告与数据追踪!
windows·macos·电脑
许泽宇的技术分享2 天前
Windows桌面自动化的革命性突破:深度解析Windows-MCP.Net Desktop模块的技术奥秘
windows·自动化·.net
七仔的博客3 天前
【摸鱼办公神器】七仔的桌面工具超进化 -> 灵卡面板 v1.1.9
windows·神器·摸鱼
码农阿豪3 天前
Windows从零到一安装KingbaseES数据库及使用ksql工具连接全指南
数据库·windows