473,405 Members | 2,287 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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(PointA.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.
Nov 21 '05 #1
4 4207
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
http://www.vb-helper.com/vbgp.htm

Tips on his web site about 3d graphics
http://www.vb-helper.com/index_graphics.html#3d

Ken
-----------------------
"Tamer via DotNetMonster.com" <fo***@DotNetMonster.com> wrote in message
news:53***********@DotNetMonster.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(PointA.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.
Nov 21 '05 #2

Tamer via DotNetMonster.com wrote:
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
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:

...
...

Dim PointA as Point, PointB as Point

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

...
...
You can say

Dim pt3A As Point3D, pt3B As Point3D

With ...
.Line(Conv3D(pt3A), Conv3D(pt3B))
End With

Where .Line is a procedure that takes two Point2D's as its arguments.

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


Better than my Italian :)

--
Larry Lard
Replies to group please

Nov 21 '05 #3
Thanks for reading, sorry for the gibberish English: I'm Italian.


Better than my Italian :)


Better than some Americans' English!!

Nov 21 '05 #4
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:
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;

[quoted text clipped - 7 lines]
z as double
End Structure


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:
...
...

[quoted text clipped - 8 lines]
...
...


You can say

Dim pt3A As Point3D, pt3B As Point3D

With ...
.Line(Conv3D(pt3A), Conv3D(pt3B))
End With

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


Better than my Italian :)

--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...b-net/200508/1
Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Lauren Quantrell | last post by:
I have a table tblCustomers in a one-to-many relationship with table tblProducts. What I want to do is to create a stored procudure that returns a list of each customer in tblCustomers but also...
10
by: Michael | last post by:
Guys, I'm interested in how the compiler implements function calls, can anyone correct my understanding/point me towards some good articles. When a function is called, is the stack pointer...
1
by: Barbara Lindsey | last post by:
I am a postgres newbie. I am trying to create a trigger that will put a copy of a record into a backup table before update or delete. As I understand it, in order to do this I must have a...
7
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I...
7
by: Jimakos Bilakis | last post by:
Hi guys! I'm using the C++ Builder 6 Enterprise Edition where I create some tables in Paradox and with the help of a structure i pass my data from the form (Edit boxes) to the Paradox table with...
16
by: mdh | last post by:
May I ask the group the following: (Again, alas , from K&R) This is part of a function: while ( ( array1 = array2 ) != '\0' ); /* etc etc */ Is this the order that this is evaluated? ...
13
by: docschnipp | last post by:
Hi, I have a bunch of object derived from the same base class. They all share the same constructor with some parameters. Now, instead of using a large switch() statement where I call every...
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
1
by: Dave | last post by:
I have multiple forms that will create an object. Basically a energy efficiency measure object. The measure object will have a couple of required properties set but after that it can have 10-20...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.