Results 1 to 8 of 8

Thread: I would like to create a very simple 3D Vector library

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2017
    Posts
    6

    Question I would like to create a very simple 3D Vector library

    Hi, I am concentrating on math at this time and I am learning about 3D rendering and the math involved. At this time I am going through some tutorials on Vectors, so I have a simple understanding of the basics. My main resource for this is khanacademy_org.

    I am using Visual Basic .NET 2017 Community edition and I would like to create a 3D Vector library. The user will end up having a Vector3f type for example and will be able to do some basic operations on it.

    I need help getting started with this both as a math concept and also as an implementation in Visual Basic. So that the library is useful rather than something that slows down the program.

    So what would be the best way to organize this and should I use Structures, Classes and etc. What operations do I need to have as a minimum and how would the operations be represented in Visual Basic, so I can perform arithmetic operations on the Types.

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Re: I would like to create a very simple 3D Vector library

    Is this more for instruction or utility? The reason I ask is that the best library is one that you don't have to maintain, but that isn't true if the main purpose of the exercise is to learn the math, learn the concepts, and so on. If the point is just to have a library, then you might look at this:

    https://numerics.mathdotnet.com/

    Along with the Vector and Matrix classes from MSDN (though the obvious ones I found appear to be 2D, rather than 3D).
    My usual boring signature: Nothing

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2017
    Posts
    6

    Re: I would like to create a very simple 3D Vector library

    The main purpose is to learn and better understand the math. For this reason, I would like to start with skeleton code and complete a small vector sample. Thank you for the mathdotnet link. In fact I would like to create a library like that for my own everyday use. That is, I am learning only, but I want to emulate regular usage of what I create so eventually I might turn it into something more professional.

  4. #4

    Thread Starter
    New Member
    Join Date
    Nov 2017
    Posts
    6

    Re: I would like to create a very simple 3D Vector library

    I realized that I can ask a better question. Instead of going deep into a discussion about vectors, maybe someone can answer this related question.

    .NET has a Point type or class. Instead I would create my own.

    So to best make use of my own Point type, what should I do? Should I create a ...

    Public Class Point
    Public x As Integer
    Public y As Integer
    End Class

    In other words, it seems simple. I create that class then compile it into a Class Library and it has it's own Namespace, so I load it into a project and use it. But this is without any thought about optimization or correct design.

    A couple of questions about that I have are: Should I use a Struct or a Class. Should I use an Integer or the x and y. Should I add any attributes to the class and how would I select the right attributes if I should. Do I need to change anything in the base class related to math operations? When I get to vectors, I will need to add operations such as vector addition and subtraction. For that I think to be correct, I might have to change or overload something, otherwise they are just added functions.

    Hopefully, my question is better this way.

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    Re: I would like to create a very simple 3D Vector library

    Quote Originally Posted by ic3pixel View Post
    A couple of questions about that I have are: Should I use a Struct or a Class.
    In almost all cases you use a Class rather than a Struct, as a Class allows more functionality, and is a bit easier to use it (eg: you can change just the X property, without having to create a new instance and copying the Y over).

    As you want to add functionality to it (rather than just data), a Class would be the way to go.
    Should I use an Integer or the x and y.
    Do you think they should always contain whole numbers?

    Do you think they should always be in the range of values that the Integer data type supports?

    If the answer is Yes to both of those then Integer is fine, but if the answer to either is No then you need a different data type. If you aren't sure, you can change the data type later when you have a clearer idea.

    Should I add any attributes to the class and how would I select the right attributes if I should.
    If you don't already know what to add, it is probably best to not add anything yet... add them if/when you know what you need.

    Do I need to change anything in the base class related to math operations? When I get to vectors, I will need to add operations such as vector addition and subtraction. For that I think to be correct, I might have to change or overload something, otherwise they are just added functions.
    You can overload the standard operators like + etc, but I can't remember the details of how at the moment (it isn't quite as easy as it is for methods, but is isn't much harder).

  6. #6

    Thread Starter
    New Member
    Join Date
    Nov 2017
    Posts
    6

    Re: I would like to create a very simple 3D Vector library

    Ok, I will work with that. Thanks.

  7. #7
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Re: I would like to create a very simple 3D Vector library

    In general, I agree with everything that Si said, however, I would also point out that MS made the Point a Structure, and there's a PointF which is a structure using floating point values rather than integers. Floating point is almost certainly what you will need for any 3D matrix math, so you might as well just start out that way, using Doubles as the type.

    So, why did MS use structures? There are limitations on structures, such as wanting to keep the number of members small (a point would have either two or three member variables, depending on whether you are 2D or 3D, so that's small), and to not be using reference types. Doubles aren't reference types, so you've got that, too. Since you meet those criteria, I believe that a structure will be ever so slightly faster in some things, which may be the reason that MS used structures for Point and PointF. They are different, though, and can trip you up, especially if you use them in arrays (or maybe it's lists, I forget).

    I totally support the idea of building this library as a means to learn. It should be good for that.

    You may want to have all your structures implement IEquatable(of T), and may consider IComparable(of T). The first would allow you to overload the = and <> operators, which are pretty convenient. The latter would allow you to sort collections, and use > or <, but when it comes to a Point (of any sort), there generally isn't a good, standard, way to do that kind of comparison.
    My usual boring signature: Nothing

  8. #8

    Thread Starter
    New Member
    Join Date
    Nov 2017
    Posts
    6

    Re: I would like to create a very simple 3D Vector library

    If I have a 3d point and eventually want to translate it to a 2d screen coordinate. Should I also create an integer Point, or is it more sensible to rely on the graphics system to plot this? Even for learning purposes that might be overdoing it no?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width