How I do create a function that returns two different values?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tamer via DotNetMonster.com

    #1

    How I do create a function that returns two different values?

    I'm developing a graphic engine. I got all equations made, I need only to
    understand how I can create a function that, once accepted three values (x;
    y; z), it returns the two values (X; Y) coming from two distinct mathematical
    processes. I don't want to use another global variable, I'm trying to be fast,
    in order to use such a function even in this way:

    Public Structure Point
    x as double
    y as double
    z as double
    End Structure

    ....
    ....

    Dim PointA as Point, PointB as Point

    With ...
    .Line(Conv3D(Po intA.x, PointA.y, PointA.z)) - (Conv3D(PointB. x,
    PointB.y, PointB.z))
    End With

    ....
    ....

    And so on.
    Thanks for reading, sorry for the gibberish English: I'm Italian.
  • Ken Tucker [MVP]

    #2
    Re: How I do create a function that returns two different values?

    Hi,

    Rod Stephens book Visual Basic Graphics Programing covers how to do
    it. The book has sample apps that are written in vb6 but you can see how to
    do the math.

    Book


    Tips on his web site about 3d graphics


    Ken
    -----------------------
    "Tamer via DotNetMonster.c om" <forum@DotNetMo nster.com> wrote in message
    news:53697AE088 C78@DotNetMonst er.com...
    I'm developing a graphic engine. I got all equations made, I need only to
    understand how I can create a function that, once accepted three values (x;
    y; z), it returns the two values (X; Y) coming from two distinct
    mathematical
    processes. I don't want to use another global variable, I'm trying to be
    fast,
    in order to use such a function even in this way:

    Public Structure Point
    x as double
    y as double
    z as double
    End Structure

    ....
    ....

    Dim PointA as Point, PointB as Point

    With ...
    .Line(Conv3D(Po intA.x, PointA.y, PointA.z)) - (Conv3D(PointB. x,
    PointB.y, PointB.z))
    End With

    ....
    ....

    And so on.
    Thanks for reading, sorry for the gibberish English: I'm Italian.


    Comment

    • Larry Lard

      #3
      Re: How I do create a function that returns two different values?


      Tamer via DotNetMonster.c om wrote:[color=blue]
      > I'm developing a graphic engine. I got all equations made, I need only to
      > understand how I can create a function that, once accepted three values (x;
      > y; z), it returns the two values (X; Y) coming from two distinct mathematical
      > processes. I don't want to use another global variable, I'm trying to be fast,
      > in order to use such a function even in this way:
      >
      > Public Structure Point
      > x as double
      > y as double
      > z as double
      > End Structure[/color]

      The .NET Framework already includes a structure named Point (in
      System.Drawing) , so you should probably choose a different name for
      your point structure, just to avoid any confusion. Maybe Point3D ? And
      Point2D for your points on a plane? (Note that you probably shouldn't
      use System.Drawing. Point for your 2D points, unless you are actually
      using System.Drawing. Point itself).

      Now, once you've got these two structures defined:

      Public Structure Point3D
      X As Double
      Y As Double
      Z As Double
      End Structure


      Public Structure Point2D
      X As Double
      Y As Double
      End Structure

      it's then just a matter of defining your conversion function such that
      it accepts a Point3D and returns a Point2D. Depending on your
      application, it may or may not make sense to make this conversion
      function a member of Point3D. In this example I won't.

      Public Function Conv3D(ByVal FromPoint As Point3D) As Point2D
      Dim p As Point2D

      'do the calculations
      p.X = FromPoint.X
      p.Y = FromPoint.Y + FromPoint.Z

      Return p
      End Function


      Once you have done that, to do this kind of thing:
      [color=blue]
      >
      > ...
      > ...
      >
      > Dim PointA as Point, PointB as Point
      >
      > With ...
      > .Line(Conv3D(Po intA.x, PointA.y, PointA.z)) - (Conv3D(PointB. x,
      > PointB.y, PointB.z))
      > End With
      >
      > ...
      > ...[/color]

      You can say

      Dim pt3A As Point3D, pt3B As Point3D

      With ...
      .Line(Conv3D(pt 3A), Conv3D(pt3B))
      End With

      Where .Line is a procedure that takes two Point2D's as its arguments.
      [color=blue]
      >
      > And so on.
      > Thanks for reading, sorry for the gibberish English: I'm Italian.[/color]

      Better than my Italian :)

      --
      Larry Lard
      Replies to group please

      Comment

      • Chris Dunaway

        #4
        Re: How I do create a function that returns two different values?

        [color=blue][color=green]
        > > Thanks for reading, sorry for the gibberish English: I'm Italian.[/color]
        >
        > Better than my Italian :)
        >[/color]

        Better than some Americans' English!!

        Comment

        • Tamer via DotNetMonster.com

          #5
          Re: How I do create a function that returns two different values?

          Thank you very much, really! Well I come from some VB6 and QBasic programming
          experience, so I completely missed the fact that I can declare a function as
          a structure of my own... Thinking about it, now it makes me sense.

          For the "point matter", well... I now that already exist a Point function.
          I've using it for years for the conversion from 32bit colour information to
          RGB (until yesterday, when I discovered GetRed, GetGreen and GetBlue function)
          ..
          I'm actually using Point3D and Point2D structures (you're a mind-reader, uh?),
          with xPt, yPt and zPt elements.

          So, thanks a lot for your precious advice; as we say in Italy, I was getting
          lost into a glass of water.
          Tamer



          Larry Lard wrote:[color=blue][color=green]
          >> I'm developing a graphic engine. I got all equations made, I need only to
          >> understand how I can create a function that, once accepted three values (x;[/color]
          >[quoted text clipped - 7 lines][color=green]
          >> z as double
          >> End Structure[/color]
          >
          >The .NET Framework already includes a structure named Point (in
          >System.Drawing ), so you should probably choose a different name for
          >your point structure, just to avoid any confusion. Maybe Point3D ? And
          >Point2D for your points on a plane? (Note that you probably shouldn't
          >use System.Drawing. Point for your 2D points, unless you are actually
          >using System.Drawing. Point itself).
          >
          >Now, once you've got these two structures defined:
          >
          >Public Structure Point3D
          > X As Double
          > Y As Double
          > Z As Double
          >End Structure
          >
          >Public Structure Point2D
          > X As Double
          > Y As Double
          >End Structure
          >
          >it's then just a matter of defining your conversion function such that
          >it accepts a Point3D and returns a Point2D. Depending on your
          >application, it may or may not make sense to make this conversion
          >function a member of Point3D. In this example I won't.
          >
          > Public Function Conv3D(ByVal FromPoint As Point3D) As Point2D
          > Dim p As Point2D
          >
          > 'do the calculations
          > p.X = FromPoint.X
          > p.Y = FromPoint.Y + FromPoint.Z
          >
          > Return p
          > End Function
          >
          >Once you have done that, to do this kind of thing:
          >[color=green]
          >> ...
          >> ...[/color]
          >[quoted text clipped - 8 lines][color=green]
          >> ...
          >> ...[/color]
          >
          >You can say
          >
          > Dim pt3A As Point3D, pt3B As Point3D
          >
          > With ...
          > .Line(Conv3D(pt 3A), Conv3D(pt3B))
          > End With
          >
          >Where .Line is a procedure that takes two Point2D's as its arguments.
          >[color=green]
          >> And so on.
          >> Thanks for reading, sorry for the gibberish English: I'm Italian.[/color]
          >
          >Better than my Italian :)
          >[/color]


          --
          Message posted via DotNetMonster.c om
          Best online pokies for real money in Australia and learn about safety and game mechanics in this comprehensive guide.

          Comment

          Working...