我正在编写一个包含BezierPoints列表的BezierPath类.每个BezierPoint都有一个位置,一个inTangent和一个outTangent:

BezierPath包含从路径获取线性位置和切线的函数.我的下一步是提供从路径中获取法线的功能.
我知道3D中的任何给定线都将具有无限数量的垂直线,因此不会有一个设定的答案.
我的目标是让用户能够在每个BezierPoint上指定法线(或滚动角?),我将在它之间进行插值以获得沿路径的法线.我的问题是我不知道如何选择起始切线(默认切线应该是什么?).
我第一次尝试获取起始切线是使用Unity3D方法Quaternion.LookRotation:
Quaternion lookAt = Quaternion.LookRotation(tangent);
Vector3 normal = lookAt * Vector3.up;
Handles.DrawLine(position, position + normal * 10.0f);
Run Code Online (Sandbox Code Playgroud)
这导致以下结果(绿线是切线,蓝线是法线):

在大多数情况下,这似乎是一个很好的基础结果,但看起来在某些方向上有突然的变化:

所以我的问题是:是否有一种很好的方法可以获得3D中线条的一致默认法线?
谢谢,Ves
我有一个类型的集合,我想过滤掉每个不具体的类型.
我可以看到我可以检查isAbstract和isInterface以捕获大多数非混凝土,但这会错过任何东西吗?
是否有"isConcrete"属性?
我正在使用 C# 中的一个库,其中的方法要求我将目标方法的字符串名称作为参数传递。
出于显而易见的原因,我想避免使用硬编码字符串,因此我将编写一个中间 util 方法,该方法采用一个方法,获取名称(大概通过反射)并将其输入到库方法中。
我希望中间方法看起来像这样:
public void CallOtherMethod(???? inputMethod)
{
string methodName = inputMethod.Name; // This gives me the method without the namespace, right?
this.CallFinalMethod(methodName);
}
Run Code Online (Sandbox Code Playgroud)
像这样调用:
this.CallOtherMethod(this.SomeOtherMethod);
Run Code Online (Sandbox Code Playgroud)
但是,我在确定执行此操作所需的类型时遇到了一些麻烦。
我怎样才能正确定义我的方法?
作为旁注,我很乐意将其编写为库的扩展方法,但这不太适合库的行为方式。
我正在尝试做这样的事情:
public class MySuperCoolClass<T>
{
public T? myMaybeNullField {get; set;}
}
Run Code Online (Sandbox Code Playgroud)
这可能吗?
这给了我错误:
错误CS0453:
T' must be a non-nullable value type in order to use it as type parameter泛型类型或方法System.Nullable'中的类型T'.
谢谢
我正在编写一个网络应用程序,其中id请求对象,并通过委托回调返回:
public static void requestById<ModelType>(T id, Action<ModelType> callback)
where ModelType : AbstractModel<T>
{
}
Run Code Online (Sandbox Code Playgroud)
为方便起见,我有一种方法可以一次请求多个对象:
public static void requestByIds<ModelType>
(List<T> ids, Action<List<ModelType>> callback)
where ModelType : AbstractModel<T>, new()
{
}
Run Code Online (Sandbox Code Playgroud)
接下来我有一个抽象的模型对象,它有多个子节点,以及一个请求它的子节点的方法:
public abstract void requestSections(Action<List<AbstractSection>> callback);
Run Code Online (Sandbox Code Playgroud)
然后是具体类中的实现:
public override void requestSections(Action<List<AbstractSection>> callback)
{
Section.requestByIds<Section>(this.sectionIds, callback);
}
Run Code Online (Sandbox Code Playgroud)
突然间,我找到了代表
Action<List<AbstractSection>>
Run Code Online (Sandbox Code Playgroud)
与...不相容
Action<List<Section>>
Run Code Online (Sandbox Code Playgroud)
这是C#中逆变的限制吗?有没有任何解决方法,所以我可以让我的覆盖方法工作?谢谢
我正在尝试执行以下操作:
int count = 50;
List<float> myList = new List<float>(50);
output[0] = 0.0f;
Run Code Online (Sandbox Code Playgroud)
但我得到错误:
ArgumentOutOfRangeException: Argument is out of range.
Parameter name: index
Run Code Online (Sandbox Code Playgroud)
显然,我误解了List(或者任何其他集合?)的初始容量是什么.有人可以向我解释一下初始容量是多少?