Tag: 相交

在XNA中与3D四边形相交?

所以我成功制作了一个代表鼠标未被投射到世界的光线,现在我需要检查光线是否可以与四边形物体相交,这是我用来获取光线的代码: public Ray GetMouseRay() { Vector2 mousePosition = new Vector2(cursor.getX(), cursor.getY()); Vector3 nearPoint = new Vector3(mousePosition, 0); Vector3 farPoint = new Vector3(mousePosition, 1); nearPoint = viewport.Unproject(nearPoint, projectionMatrix, viewMatrix, Matrix.Identity); farPoint = viewport.Unproject(farPoint, projectionMatrix, viewMatrix, Matrix.Identity); Vector3 direction = farPoint – nearPoint; direction.Normalize(); return new Ray(nearPoint, direction); } 同样,这是我的四元结构,我用它在3d空间中绘制一个“立方体世界”。 public struct Quad {public Vector3 Origin; public […]

在linq中为什么后续调用IEnumerable.Intersect这么快

在看这个问题C#两个数组的相似性时,注意到初始linq调用明显慢于后续调用。 正在缓存什么才能产生这样的差异? 我感兴趣的是什么时候我们可以期望实现这种类型的行为(也许这只是因为相同的列表被反复使用)。 static void Main(string[] args) { var a = new List() { 7, 17, 21, 29, 30, 33, 40, 42, 51, 53, 60, 63, 66, 68, 70, 84, 85, 91, 101, 102, 104, 108, 109, 112, 115, 116, 118, 125, 132, 137, 139, 142, 155, 163, 164, 172, 174, 176, 179, 184, 185, […]

c#词典相交

我有关于Linq / Lambda的问题以及以下问题: 我有两个词典,主要和次要……这两个词典被定义为Key = string,Value = int。 如果KEYS与辅助字典相交,我需要修剪主字典。 即: primaryDict = [“thing1”, 33] [“thing2”, 24] [“thing3”, 21] [“thing4”, 17] [“thing5”, 12] secondaryDict = [“thing1”, 22] [“thing3”, 20] [“thing4”, 19] [“thing7”, 17] [“thing9”, 10] resultDict = [“thing1”, 33] [“thing3”, 21] [“thing4”, 17] 我的尝试: resultDict = primaryDict.Keys.Intersect(secondaryDict.Keys).ToDictionary(t => t.Key, t.Value); 这显然不起作用,因为primaryDict.Keys.Intersect返回一个键列表…我将如何重新建立一个新词典,或者配对主词典? 任何帮助,将不胜感激。

C#Linq与对象的一部分相交/除外

我环顾四周,在这里找不到任何帮助。 我有一节课: class ThisClass { private string a {get; set;} private string b {get; set;} } 我想使用Linq的Intersect和Except方法,即: private List foo = new List(); private List bar = new List(); 然后我单独填写两个列表。 我想做,例如(我知道这不对,只是伪代码),如下: foo[a].Intersect(bar[a]); 我该怎么办? 谢谢你的帮助 :)