Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vector3 direction and Plane distance #24713

Closed
ghost opened this issue Jan 18, 2018 · 27 comments
Closed

Vector3 direction and Plane distance #24713

ghost opened this issue Jan 18, 2018 · 27 comments
Labels
area-System.Numerics question Answer questions and provide assistance, not an issue with source code or documentation.
Milestone

Comments

@ghost
Copy link

ghost commented Jan 18, 2018

SIMD-Enabled types are poorly documented, so I need to ask about two things:

  1. Vectors are defined by only one point . Does this mean that its direction is from the origin point to that point?

  2. The Plane structure is defined by a Vector3 normal to it and a distance. If normal vector starts from the origin to a point on the plane surface, why do we need a distance? What does it mean? Or if the point of the vector is not on the plane surface, what does it mean?
    Maybe I miss something, but as I said, documents doesn't help. So, what do you really mean with this implementation?

  3. I suggest adding a constructor to the Plane Structure, that has one parameter "normal" of type Vector3. It can get the distance frome:
    d = normal.Length.
    This is usefull when we know the intersection point of the normal vector with the plane.

And please, make the documantaion more detailed.
Thanks.

@mikedn
Copy link
Contributor

mikedn commented Jan 18, 2018

Vectors are defined by only one point. Does this mean that its direction is from the origin point to that point?

That's really up to you. A vector has a direction and a length (aka magnitude) but it does not have a position in space. If you place the vector in origin then it happens so that its components are identical to the coordinates of the vector's end point.

If normal vector starts from the origin to a point on the plane surface, why do we need a distance?

As already stated, vectors do not have a fixed position in space. In particular, normal vectors solely indicate direction. They also usually have unit length.

For planes the normal indicates the direction of the plane and the distance indicates the distance between the plane and the origin of the coordinate system.

And please, make the documantaion more detailed.

The documentation of types such as Vector3 and Plane isn't a math book.

@ghost
Copy link

ghost commented Jan 18, 2018

Thanks @mikedn.
But, could you explain the direction of the vector? We only suply one point. What does it mean?

The documentation of types such as Vector3 and Plane isn't a math book.

Yes, but it should refer to the math standerds used with this type. I'm an engineer but I couldn't understand how these work even after looking at source code and reading some topics in Wikipedia.
Give us a hint about what you are doing. Maybe you depend on previous experience with unity or other mathematical libraries, but this is new to C# and Vb.net programmers.

@tannergooding
Copy link
Member

but this is new to C# and Vb.net programmers.

Like many types, it also isn't necessarily designed for "general" use. There are a multitude of APIs that require some prior knowledge or experience to use them. Much of the System.Numerics APIs require some knowledge of higher mathematics (The Vector types require some background in Linear Algebra).

Yes, but it should refer to the math standerds used with this type.

I don't think there is any "standard" for these. Its mathematical rules/concepts and the best open resource might be Wikipedia or some random blog post.

But, could you explain the direction of the vector? We only suply one point. What does it mean?

https://en.wikipedia.org/wiki/Euclidean_vector

If you have a vector (1, 2, 3), then the direction is +1 along the X axis, +2 along the Y axis, and +3 along the Z axis. This is from whatever the "origin" point is (which may be implicit, but is data external to the vector itself)

@mikedn
Copy link
Contributor

mikedn commented Jan 18, 2018

But, could you explain the direction of the vector? We only suply one point. What does it mean?

Hmm, if you want to treat a vector (x, y, z) as a point then think of it as an arrow that starts from origin and ends in the point (x, y, z). That arrow has a length and a direction (basically the angle between the arrow and the X axis). Now move this arrow from origin but do not alter its length or direction. What you get is the same (x, y, z) vector.

It may be more useful if you try to map the abstract concept of vector to something from the real world - velocity for example. The velocity of a moving object is a vector and like all vectors has a length and a direction. The length tells you the speed of the object. The direction tells you where the objects goes (left, right etc.). The velocity does not tell you where the object is, its position.

Maybe you depend on previous experience with unity or other mathematical libraries, but this is new to C# and Vb.net programmers.

It's all math really. It has nothing to do with programming.

@ghost
Copy link

ghost commented Jan 18, 2018

@tannergooding
There are different types of vectors, as in Wikipedia

Being an arrow, a Euclidean vector possesses a definite initial point and terminal point. A vector with fixed initial and terminal point is called a bound vector.[9] When only the magnitude and direction of the vector matter, then the particular initial point is of no importance, and the vector is called a free vector. Thus two arrows A B → {\displaystyle {\overrightarrow {AB}}} {\overrightarrow {AB}} and A ′ B ′ → {\displaystyle {\overrightarrow {A'B'}}} {\overrightarrow {A'B'}} in space represent the same free vector if they have the same magnitude and direction: that is, they are equivalent if the quadrilateral ABB′A′ is a parallelogram. If the Euclidean space is equipped with a choice of origin, then a free vector is equivalent to the bound vector of the same magnitude and direction whose initial point is the origin.

This is why I asked what the implementation means.
I wanted to make sure that the first point of the vector is the origin.

@ghost
Copy link

ghost commented Jan 18, 2018

@mikedn
I disagree with the "has no pos" part. Vector.Length calculates the length of the vector supposing it starts from origin to the point.
The implementer should give us some hints about what he is doing and aiming.

@mikedn
Copy link
Contributor

mikedn commented Jan 18, 2018

I disagree with the "has no pos" part. Vector.Length calculates the length of the vector supposing it starts from origin to the point.

What makes you think that?

The implementer should give us some hints about what he is doing and aiming.

Huh? Apparently you're still confusing math with programming.

@gfoidl
Copy link
Member

gfoidl commented Jan 19, 2018

Length has nothing to do with the position. || End - Start || so it's relative. Or look at the component form, and you'll see that the origin doesn't matter.

@ghost
Copy link

ghost commented Jan 19, 2018

@gfoidl
You may say so, if Vector3 is defirnd by two points of your choice. But it's relative to the origin only as the start point, and you only suply the end point, so it has a fixed pos. This is why I keep asking about what the implementer means.

@mikedn
Copy link
Contributor

mikedn commented Jan 19, 2018

But it's relative to the origin only as the start point, and you only suply the end point, so it has a fixed pos.

You've already been told that a vector doesn't have an associated position in space. It's sometimes useful to think that a vector starts in origin (or wherever else makes sense in a given context) but the fact is that the position information isn't encoded in a vector, only its direction and length are.

@ghost
Copy link

ghost commented Jan 19, 2018

@mikedn
To be sure: do you mean that the vector x,y,z represents any parallel vector with he same angle, length and direction, regardless passing through the x,y,z point ?
Or do you mean that the vector can be infinite number of segments along the line crossing the two points 0,0,0 and x,y,z.
Position may have different meanings!

@mikedn
Copy link
Contributor

mikedn commented Jan 19, 2018

do you mean that the vector x,y,z represents any parallel vector with he same angle and length and direction

Exactly.

Another way of looking at it is that the x, y and z components of a vector represent the length of vector's projection on the X, Y and Z axes of the coordinate system. And given the length of these projections the vector's length is sqr(x*x + y*y + z*z), something that can be demonstrated even by using elementary geometry concepts such as Pythagoras's theorem.

The angle(s) that give you the direction can also be computed using basic trigonometry concepts even though when you're using vectors you're more likely to resort to using the dot product rather than actual trigonometry formulas.

Nowhere in these calculations do any point coordinates appear, it's all about lengths and proportions.

@ghost
Copy link

ghost commented Jan 21, 2018

@mikedn
This is a good example showing why I keep asking the implementers about their conventions and why not putting them in the documentation:
dotnet/corefx#26497

@tannergooding
Copy link
Member

As stated in the issue you linked, the implementation isn't following any convention but the standard mathematical rules for these types (generally using the rules for Euclidean Space).

@ghost
Copy link

ghost commented Jan 22, 2018

@mikedn
In this example, the normal vectors for the planes P1 and P2 are identical, although the two planes are parallel and in oposite directions of the Z axis.

            var P1 = Plane.CreateFromVertices(
                            new Vector3(0, 0, 10), 
                            new Vector3(6, 0, 10), 
                            new Vector3(3, 4, 10));
            Console.WriteLine(P1.Normal.ToString()); // <0, 0, 1>

            var P2 = Plane.CreateFromVertices(
                           new Vector3(0, 0, -10), 
                           new Vector3(6, 0, -10), 
                           new Vector3(3, 4, -10));
            Console.WriteLine(P2.Normal.ToString()); // <0, 0, 1>

This indicates that the origin is not always the start point of the vector, which is strang and confusing! What is the rule used here if this is not a bug?
It is always a good thing to state the basic conventions in documents. At least we can report bugs when we know they are bugs!!
Also, I'm not comfortable with the implementation of the vector as a single point. In the code you see that Vector3 parameters are treated as points!! I would prefer to define a vector with start and end points and have properties or methods to calculate angles. If you have a vector AB not passing through the origin, you will have to do some calculations to find the correct point to define Vector2 ar vector3 in current implementaion! Or at least add a constructor to Vector structures thar accepts two points, so the subtraction of the two points to get the vectors end point can be optimized as SIMD operations.

@tannergooding
Copy link
Member

See the response I gave here: https://github.com/dotnet/corefx/issues/26497#issuecomment-359320608.

The .NET implementation is not doing anything drastically different from any other major vector math library in production use today.

@mikedn
Copy link
Contributor

mikedn commented Jan 22, 2018

This is a good example showing why I keep asking the implementers about their conventions and why not putting them in the documentation:

Also, I'm not comfortable with the implementation of the vector as a single point. In the code you see that Vector3 parameters are treated as points!! I would prefer to define a vector with start and end points and have properties or methods to calculate angles. If you have a vector AB not passing through the origin, you will have to do some calculations to find the correct point to define Vector2 ar vector3 in current implementaion!

The only thing that it is showing is that you have no clue what you are talking about (which is not a bad thing by itself, nobody's born knowing everything) but at the same time you're arrogant enough to claim that these types are somehow broken and suggest "improvements". In reality, the only thing that is broken here is your attempt at using math tools without knowing math and then blame it on "implementers" for not explaining clearly how their implementation deviates from your imagination.

@ghost
Copy link

ghost commented Jan 22, 2018

@mikedn
I have some background in math as I studied electrical and communications years ago, before I became a programmer. But I'm not expert in theoretical math. Things like vectors and planes of course can be found in high school courses.
I study SIMD-Enabled types to be familiar with for any future use. In programming you can expect to need any part of the language anytime.
It's not about being arrogant to ask for simplicity and clarity and more capabilities. Obviously, these new types need a significant learning time, and documents don't give much details, not about math itself of source, but at least about important notes on special inputs and outputs.
So, unlike you think, I got a lot of information from this discussion. You completed the missing parts in the documents, so thanks a lot :). You can save yourselves a lot of time if you put some more info in the documents.

@mikedn
Copy link
Contributor

mikedn commented Jan 22, 2018

I study SIMD-Enabled types to be familiar with for any future use

That's part of the problem. You keep insisting in studying these "types" (and btw, the SIMD aspect is completely irrelevant) when in fact you should be studying the math behind these "types". Without the math these types aren't very useful.

It's not about being arrogant to ask for simplicity and clarity and more capabilities.

If you learn the math you'll find that these types are pretty simple and clear. And in those rare circumstances where the docs omit mentioning implementation choices (e.g. I don't think that the docs mention anywhere the choice of coordinate systems hand-ness) you'll find that it's pretty easy to figure it out by yourself. Of course, that's not an excuse for such information to not be included in the docs. It's just that it's a rather minor problem.

As for adding more capabilities, well, let's see:

I suggest adding a constructor to the Plane Structure, that has one parameter "normal" of type Vector3.

In many cases normal vectors are normalized, that is, they have length = 1. Some computations simply require normalized vectors for correctness purposes. In other cases normalized vectors are not required but they're used to avoid issues with floating point precision. And normalized or not, normal vectors can't have length = 0, they'd lose the direction information. So it's kind of bizarre to have a Plane constructor such as the one you describe.

Or at least add a constructor to Vector structures thar accepts two points, so the subtraction of the two points to get the vectors end point.

As repeatedly stated previously vectors do not have a position in space so it's not clear what you mean by end point. Vectors can be used to represent many things (normals, velocities etc.) and they can also be used to represent positions in space (aka positions vectors). Then you have 2 vectors (v1 and v2) that represent 2 points in space then the vector that gives you the distance and direction between those points is v2 - v1 (or v1 - v2 depending on what you need exactly). In short, there is no need to add a vector constructor that does an operation that's already available via the subtraction operator.

can be optimized as SIMD operations

I'm getting the impression that you think that these types might be useful to you not due to the math concepts they're supposed to represent but due to the SIMD stuff. That's really the wrong way to look at SIMD, if you need SIMD then use Vector<T>, not Vector2/3/4.

@ghost
Copy link

ghost commented Jan 22, 2018

I'm getting the impression that you think that these types might be useful to you not due to the math concepts they're supposed to represent but due to the SIMD stuff. That's really the wrong way to look at SIMD, if you need SIMD then use Vector, not Vector2/3/4.

This exactly my problem, becuase of how you announced these types in what's new :)
In the beginning I looked at Matrix2x3 and Matrix4x4 and vectors as means for doing some algebraic calculations in parallel using SIMD. This can be helpful in algorithms other than graphics.
When I got to the Plane Structure, things became geometric and I couldn't found any hint in documents about directions and etc. It seems as if this was a graphical library in strange namespace. One could ask about other geometric operations such as intersection between two planes? A brief introductions about areas these SIMD types aimed for, and their limits can be helpful. Graphical applications use other tools such as DirectX, so who can use these types?
That's where my problem came from. You keep saying: this is not meant for you! I keep thinking: a programming language is general purpose, and I need to take a look about new features to put them in my toolbox.
So, I hope you are not angry. I read about topics came across this discussions, remembered some things I forgot about, and learned new things. So, thanks.
But, why is Vector < T > not a part of Framework yet? Documants says it is a part of System.Numerics, but it not found.

@mikedn
Copy link
Contributor

mikedn commented Jan 22, 2018

In the beginning I looked at Matrix2x3 and Matrix4x4 and vectors as means for doing some algebraic calculations in parallel using SIMD.

Hmm, the Matrix types are not using SIMD (except perhaps for some methods that happen to use Vector2/3/4 but that's pretty much irrelevant). Same for Plane and Quaternion. For example Plane uses Vector3 in CreateFromVertices and thus takes advantage of SIMD indirectly. But methods such as Dot and Transform do not have anything to do with SIMD.

I'm not sure what lead you to believe that these types are using SIMD. If there's something in the docs that makes you think that then it would be useful to point to the relevant doc pages, they definitely need to be improved/fixed.

A brief introductions about areas these SIMD types aimed for, and their limits can be helpful. Graphical applications use other tools such as DirectX, so who can use these types?

They can be used by anyone who needs vector operations for whatever purpose. But they're really targeted at 3D graphics and collision detection, as used in games. They're probably less useful for, say, scientific applications, in part due to the fact that these types use float rather than double. They trade precision for efficiency and in scientific applications you may need to do the opposite.

For general purpose SIMD the only thing that matters is Vector<T>. Vector4 might be useful on occasion but Vector2/3 are next to useless as far as SIMD is concerned. They're inefficient and have less features compared to Vector<T>.

But, why is Vector < T > is not a part of C#? Documants says it is a part of System.Numerics, but it not found.

You probably didn't add the System.Numerics.Vectors package to your project.

@ghost
Copy link

ghost commented Jan 22, 2018

If there's something in the docs that makes you think that then it would be useful to point to the relevant doc pages, they definitely need to be improved/fixed.

https://docs.microsoft.com/en-us/dotnet/framework/whats-new/

SIMD-enabled types
The System.Numerics namespace now includes a number of SIMD-enabled types, such as Matrix3x2, Matrix4x4, Plane, Quaternion, Vector2, Vector3, and Vector4.

also in System.​Numerics Namespace : https://docs.microsoft.com/en-us/dotnet/api/system.numerics?view=netframework-4.7.1

•The SIMD-enabled vector types, which include Vector2, Vector3, Vector4, Matrix3x2, Matrix4x4, Plane, and Quaternion.

@ghost
Copy link

ghost commented Jan 23, 2018

@mikedn
When I spoke about bound vectors, I was thinking more of lines. Maybe we need a Line Structure defined with two Vector3 points that the line passes through. This structure needed to get the intersection between two planes.

By the way, I was not wrong when I talked about vectors pos.

Some vector types are localized in space. These are called localized or bound vectors. These vectors start or finish at a particular point in our coordinate system. To fully specify a bound vector we need to specify this point as well as a magnitude and direction. (We only need specify one point the other is given by the magnitude and direction.) Good examples of bound vectors are the displacement vector, the position vector and the moment of a force.

I quoted another lines talking about vectors types from wikipedia , among them bound vectors, in earlier posts, but you ignored it, insisting that there is only one type of vectors.
In fact a bound vector is the type of vectors I'm familiar with through my study. I kept asking about your conventions but you think there is only one math in universe. My engineering background says otherwise, the standards may differ. This is what makes us speak two different language. I had a concept about vectors that makes me lost here.
I didn't argue much because I was busy reading and trying to understand these topics. Both of us was right from his point of view.
My concern as a programmer, even if I has a mathematical background, is to have high level tools that achieve tasks in a fast and easy way. I want a plane Structure that calculates every thing in a black box and give me results, such as intersections and if a point is on the surface , etc.
My last comment in dotnet/corefx#26497 say more about this, and about the good documentation.
Thanks.

@mikedn
Copy link
Contributor

mikedn commented Jan 23, 2018

The SIMD-enabled vector types, which include Vector2, Vector3, Vector4, Matrix3x2, Matrix4x4, Plane, and Quaternion.

Yeah, that stuff is IMO misleading. I think you should open an issue in the docs repository to have this at least discussed a bit if not fixed. As already mentioned, matrices and some other System.Numerics make no or little use of SIMD. This, combined with the fact that the .NET 4.7.1 page does not show Vector<T> because it is in a separate package makes things rather confusing. It looks like MS was so enthusiastic that they finally added support for SIMD that they ended up selling a bit of snake oil.

By the way, I was not wrong when I talked about vectors pos.

You're not wrong but you're not right either. The notion of bound vector exists but it is a bit of conceptual gimmick. In does not exist in vector space where the notion of vector really comes from. Nor you'll easily find a library (at least in the 3D graphics domain) that has such a type built in. It's neither efficient nor flexible to store in a type information that's not widely used/necessary.

Best example is the position vector. It's starting point is the origin of the coordinate system. But that's "by definition" so to speak. There's no need for a type with 6 components in it with the first 3 of them being always 0.

My concern as a programmer, even if I has a mathematical background, is to have high level tools that achieve tasks in a fast and easy way. I want a plane Structure that calculates every thing in a black box and give me results, such as intersections and if a point is on the surface , etc.

The System.Numerics namespace is the wrong place to look for what you want. The types provided here are "primitives", they're the basic building blocks for other types. There are a zillion geometry related concepts that are not represented in this namespace nor they will ever be - lines, segments, polygons and operations between them such as intersection, union, triangulation etc.

@ghost
Copy link

ghost commented Jan 23, 2018

@mikedn
Now we are finally on the same page. Missing bits in documents lead me to ask for things that aleady provided by Vector < T >.. NET Frameworks are expanding and difficult to follow. Net standerd leads to odd result: System.Numerics namespace has two packages, one comes as a NuGeT that has more types, even Vectors have a Reflect method that is not included in the framewoek version! This can't be good.

I think you should open an issue in the docs repository to have this at least discussed a bit if not fixed.

I opend an issue week ago about the incomplete out of date helpviewer offline topics, but no response.
Many of. NET new technologies and rheir documents are in floating state.

The types provided here are "primitives", they're the basic building blocks for other types

Do you mean you will build other types? Hope so.
You know that any programmer can build these primitives if nedded. A more specialized math library in another thing. By the way, after all these years it is still hsrd to get hardware details. WMI is not easy to use and obviously can't be used with other opersting system. I think of the framework as the tool kit where ican find all the tools I need to build my projects in any programming area, without looking out. Math is one area not only for graphics, but akso for creating educational aids for students, which is a wide area that can give. Net more popularty among students to build their own helpers.
It,'s not easy to decide the real demand of a feature. Current audience is not all the possible audience. Programing is general purpose, where every one can make his dreams true. After 15 yers of framework life, one can expect alot of it. Yes it grows in new winderfull areas, but it should not stop growing in its basic areas.
This is an option of a visual studio fan, started using it in January 1998, 20 years ago, and hope for the next 20 years of glory.
Thanks.

@mikedn
Copy link
Contributor

mikedn commented Jan 23, 2018

I opend an issue week ago about the incomplete out of date helpviewer offline topics, but no response.

Offline help viewer? Does that still exist? You'd probably get better feedback if you ask for specific things. For example, they could easily add a note to the System.Numerics namespace page about the need to use the System.Numerics.Vector package on .NET 4.7.1 to get actual SIMD support. This is mentioned on the "What's new" page but it would probably get more visibility if it was also mentioned on the namespace page.

More generally, there certainly is room for improvement in the documentation area. But I doubt that anyone will spend a lot of time adding detailed explanations about what a vector3 is and how it is supposed to be used when such information is widely available on the Internet and very much a prerequisite for using such types.

Do you mean you will build other types? Hope so.

Me? No, I do not work for MS. MS? I can't comment on their plans but I doubt they will do that. They're not in the business of making math libraries. At best they'll add some more basic stuff if people ask for it and it's not too much trouble to implement it.

You know that any programmer can build these primitives if nedded.

Yes, and many have done that already. It's likely that the main reason MS added these types is the SIMD support, that's not something that "any programmer" could have done as it requires JIT compiler & runtime support.

Math is one area not only for graphics, but akso for creating educational aids for students, which is a wide area that can give. Net more popularty among students to build their own helpers.

Yes but that doesn't mean that MS has to provide everything one may need. As already stated, they're not in the business of making a math framework. They're making a general purpose framework that also offers some math primitives. Others may use those primitives to build more advanced libraries.

@eerhardt
Copy link
Member

eerhardt commented Feb 2, 2018

I think the questions have been answered, and this issue can be closed. Please re-open if I am incorrect.

https://github.com/dotnet/corefx/issues/23448 is a general "System.Numerics.Vectors docs need to be updated" issue that we will move to https://github.com/dotnet/docs.

@eerhardt eerhardt closed this as completed Feb 2, 2018
@msftgits msftgits transferred this issue from dotnet/corefx Jan 31, 2020
@msftgits msftgits added this to the 2.1.0 milestone Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Numerics question Answer questions and provide assistance, not an issue with source code or documentation.
Projects
None yet
Development

No branches or pull requests

6 participants