What is the name of this geometrical function?
Posted
by Spike
on Stack Overflow
See other posts from Stack Overflow
or by Spike
Published on 2010-03-25T01:28:58Z
Indexed on
2010/03/25
1:33 UTC
Read the original article
Hit count: 366
In a two dimentional integer space, you have two points, A and B. This function returns an enumeration of the points in the quadrilateral subset bounded by A and B.
A = {1,1} B = {2,3}
Fn(A,B) = {{1,1},{1,2},{1,3},{2,1},{2,2},{2,3}}
I can implement it in a few lines of LINQ.
private void UnknownFunction(Point to, Point from, List<Point> list)
{
var vectorX = Enumerable.Range(Math.Min(to.X, from.X), Math.Abs(to.X - from.Y) + 1);
var vectorY = Enumerable.Range(Math.Min(to.Y, from.Y), Math.Abs(to.Y - from.Y) + 1);
foreach (var x in vectorX)
foreach (var y in vectorY)
list.Add(new Point(x, y));
}
I'm fairly sure that this is a standard mathematical operation, but I can't think what it is. Feel free to tell me that it's one line of code in your language of choice. Or to give me a cunning implementation with lambdas or some such.
But mostly I just want to know what it's called. It's driving me nuts. It feels a little like a convolution, but it's been too long since I was at school for me to be sure.
© Stack Overflow or respective owner