简体   繁体   English

如何在unity3d中创建向下的椭圆圆路径?

[英]How to create downwards elliptical circle path in unity3d?

I am new to unity3d I want to make a path for animated object. 我是unity3d的新手,我想为动画对象创建路径。 The path must be # elliptical circle # or # spring shape path # I think there is a way to draw this path based on mathematics equation is it true? 路径必须是#椭圆圆#或#弹簧形状路径#我认为有一种方法可以根据数学方程式绘制此路径,这是真的吗? or should I draw it using 3dmax. 还是我应该使用3dmax绘制它。 Any help or related tutorial for this problem? 任何有关此问题的帮助或相关教程?

thanks 谢谢

This is a helpful link for drawing a path w/ the mouse in game. 这是在游戏中用鼠标绘制路径的有用链接

If you want to draw a spring programmatically you can use a Catmullrom or Bezier spline: 如果要以编程方式绘制弹簧,则可以使用Catmullrom或Bezier样条线:

double bezier(double t, double p0,double p1,double p2,double p3){
    double t2 = t*t;
    double t3 = t2 * t;
    return (0.16667 *(  t3  *   (-p0 +  3 * p1 + -3 * p2 + p3) +    \
                    t2  *   (3 * p0 + -6 * p1 + 3 * p2) +       \
                    t   *   (-3*p0 + 3*p2) +                    \
                    1   *   (p0 + 4*p1 + p2)));
}
double catmullrom(double t, double p0,double p1,double p2,double p3){
    double t2 = t*t;
    double t3 = t2 * t;
    return (0.5 *(      (2 * p1) + (-p0 + p2) * t +(2*p0 - 5*p1 + 4*p2 - p3) * t2 +(-p0 + 3*p1- 3*p2 + p3) * t3));
}

The inputs p0,p1,p2,p3 are the 4 control points for a particular segment. 输入p0,p1,p2,p3是特定段的4个控制点。 To see a spiral building example, the rest of this code can be found on my Github page . 要查看螺旋建筑示例, 可以在我的Github页面上找到此代码的其余部分。 Look at BuildPath() in particular to see how to use those functions to build a continuous path. 特别要看BuildPath() ,以了解如何使用这些函数来构建连续路径。 I dislike linking to external accounts but my usage example is a little too big for an SO answer. 我不喜欢链接到外部帐户,但是我的用法示例对于SO答案来说太大了。

If you want to draw an ellipse, the simplest way I can think is to solve the basic equation and build a ring of points: 如果要绘制椭圆,我想到的最简单的方法是求解基本方程并建立一个点环:

List<Vector3> pts = new List<Vector3>();
for(float x=-2.0f; x<2.0f;x+=0.1){
    y = sqrt( (1-x^2/a^2) * b^2 );//from eq. x^2/a^2 + y^2/b^2=1; 
    pts.Add(new Vector3(x,y,0));
}

That code assumes you have a horizontal major axis where 'a' is the radius of the horizontal major axis, 'b' is the radius of the vertical minor axis. 该代码假定您具有水平主轴 ,其中“ a”是水平主轴的半径,“ b”是垂直短轴的半径。 Build the ellipse first along the X/Y axes and then apply whatever transform you wish to orient the ellipse. 首先沿X / Y轴构建椭圆,然后应用希望对椭圆进行定向的任何变换。

Alternatively, and I don't have code for this, you can use the general parametric equations to generate a rotated ellipse already off origin. 另外,我也没有代码,您可以使用一般参数方程式生成已经偏离原点的旋转椭圆。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM