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);
    }
}
相关推荐
是店小二呀14 小时前
远程办公自由:rdesktop+cpolar让Windows桌面随身而行
windows
油丶酸萝卜别吃15 小时前
java8中常用的工具函数
windows
Bruce_Liuxiaowei15 小时前
Win7虚拟机加入域错误排查指南:解决无法启动服务问题
运维·网络·windows·安全·网络安全
雨中风华19 小时前
Windows 平台 HOOK DWM 桌面管理程序,实现输出变形的桌面图像到显示器
windows·计算机外设
做咩啊~20 小时前
Windows家庭版远程时提示‘这可能是因为在远程计算机上阻止 NTLM 身份验证 这也可能是由于 CredSSP 加密 Oracle 修正所导致的。’
windows
淮北4941 天前
windows安装minicoda
windows·python·conda
takashi_void1 天前
如何在本地部署大语言模型(Windows,Mac,Linux)三系统教程
linux·人工智能·windows·macos·语言模型·nlp
非凡ghost1 天前
Typora(跨平台MarkDown编辑器) v1.12.2 中文绿色版
前端·windows·智能手机·编辑器·软件需求
十五年专注C++开发1 天前
CFF Explorer: 一款Windows PE 文件分析的好工具
c++·windows·microsoft
Bruce_Liuxiaowei1 天前
Windows系统错误6118全面解决方案:修复此工作组的服务器列表当前无法使用
运维·服务器·windows·网络安全