Math Help
Moderators: Fridmarr, Worldie, Aergis, Sabindeus, PsiVen
26 posts
• Page 2 of 2 • 1, 2
Re: Math Help
So long as the observer's POV is moved so that it is centered and perpendicular to any one face, regardless if the change in depth towards or away from the object, it will appear as though a two dimensional shape for your purposes.

Torquemada  Posts: 1678
 Joined: Mon Feb 04, 2008 3:00 am
 Location: Virginia
Re: Math Help
It's possible you are throwing people off by saying the outcome in 2D space needs to be a square. In your paint diagram, you have a square, a rectangle (although I have no idea how you could get that perspective on a cube), and a sixsided shape.
Are you actually looking for the profile of the object? For example, if you were to interpose a glass pane between the viewer and the object, and trace the outline of the object on the glass, the shape of that outline would be the profile of the object, regardless of its orientation with respect to the user. Effectively a onepoint perspective drawing of the object.
Is that what you are getting at?
Are you actually looking for the profile of the object? For example, if you were to interpose a glass pane between the viewer and the object, and trace the outline of the object on the glass, the shape of that outline would be the profile of the object, regardless of its orientation with respect to the user. Effectively a onepoint perspective drawing of the object.
Is that what you are getting at?
 Koatanga
 Posts: 1988
 Joined: Mon Nov 17, 2008 12:46 pm
Re: Math Help
Koatanga wrote:Are you actually looking for the profile of the object? For example, if you were to interpose a glass pane between the viewer and the object, and trace the outline of the object on the glass, the shape of that outline would be the profile of the object, regardless of its orientation with respect to the user. Effectively a onepoint perspective drawing of the object.
Is that what you are getting at?
Yes if I'm understanding you, but with a series of points. In this example the observer is the blue dot.
Depending on where the observer is in relation to the scalar field, different points become erroneous. If the observer is perpendicular to a face they see only two dimensions. If the red erroneous squares were removed, the scalar field would be "flattened" into a 2 dimensional profile. However, if the observer is not perpendicular to a face, the useful scalars are in all 3 dimensions.
Is that clear?
I know that in two dimensions, I could calculate:
atan2(MyNy,MxNx) * 180 / PI
This would give me the observer's rotation around the object. I don't know how to do this in 3 dimensions, where the observer can be anywhere in space around the scalar field. Once again, sorry for being so confusing. I guess I'm not picking my words wisely.

Jeremoot  Posts: 434
 Joined: Tue Feb 08, 2011 5:36 pm
Re: Math Help
So what you are really doing is programming a basic graphics engine for a class that can take a solid model and show a projection of it given the observer has a 2D monitor. You want a shortcut in your graphics processing to take into account that nonvisible points in your scalar field don't need to be rendered as that would waste otherwise precious processing time.
As your observer moves around your solid object it presents different aspects. Since you do not know beforehand what direction the observer will come from you need to do this graphics processing onthe fly for any given orientation of the solid.
As your observer moves around your solid object it presents different aspects. Since you do not know beforehand what direction the observer will come from you need to do this graphics processing onthe fly for any given orientation of the solid.
Never Pug a random Troll Heroic, always wait for the guild group.
Hrobearina  85 Healer  space goat
Hrobertgar  85 Tank  human
Hrobernia  85 Arcane  human
Hrobanka  85 BM  elf
Hrobearina  85 Healer  space goat
Hrobertgar  85 Tank  human
Hrobernia  85 Arcane  human
Hrobanka  85 BM  elf
 Hrobertgar
 Posts: 704
 Joined: Wed Jan 19, 2011 2:42 pm
Re: Math Help
Hrobertgar wrote:So what you are really doing is programming a basic graphics engine for a class that can take a solid model and show a projection of it given the observer has a 2D monitor. You want a shortcut in your graphics processing to take into account that nonvisible points in your scalar field don't need to be rendered as that would waste otherwise precious processing time.
Yes, essentially. But not for drawing, for doing calculations on various vertexes. Regardless, you get the idea.

Jeremoot  Posts: 434
 Joined: Tue Feb 08, 2011 5:36 pm
Re: Math Help
Jeremoot wrote:I know that in two dimensions, I could calculate:
atan2(MyNy,MxNx) * 180 / PI
This would give me the observer's rotation around the object. I don't know how to do this in 3 dimensions, where the observer can be anywhere in space around the scalar field. Once again, sorry for being so confusing. I guess I'm not picking my words wisely.
That tells you the angle with respect to the object's "axis," where presumably you're using (Mx,My) for the coordinates of the observer and (Nx,Ny) for the coordinates of the object's center. I think.
Extending to three dimensional motion of the observer requires a move from a 2D coordinate system to a 3D coordinate system, obviously. The observer now has a position (Mx,My,Mz), and any point on your object is (Nx,Ny,Nz). The angle you were calculating earlier is usually represented by phi in spherical coordinates, and you could define a second angle based on the rotation out of the xy plane into z (theta in the usual notation). Using the equations in that article, you could calculate the distance r and angles (theta, phi) from the observer to any point on the object.
For a complicated object, you'd probably need to calculate these values for every point (or a large number of representative points) in the scalar field and from there determine which points define the maximum visible extent of the object. For a cube, it should be much simpler, as you can calculate the values for 8 representative points (the corners) and from that determine which faces are visible.
Since it's a square, the fastest version is probably to calculate the angles for the closest two and farthest two vertices. Whichever of the farthest two vertices falls between the closest two is not going to be visible, nor will any of the three sides defined by that vertex. So that immediately tells you which 3 sides to draw. I imagine you can figure out the rest of the math from there. I would probably treat the observer as the "origin" for these angle calculations though, rather than relative to an arbitrary point of the cube.
"Theck, Bringer of Numbers and Pounding Headaches," courtesy of GrehnSkipjack.
MATLAB 5.x, Simcraft 6.x, Call to Arms 6.0, Talent Spec & Glyph Guide 5.x, Blog: Sacred Duty
MATLAB 5.x, Simcraft 6.x, Call to Arms 6.0, Talent Spec & Glyph Guide 5.x, Blog: Sacred Duty

theckhd  Moderator
 Posts: 7852
 Joined: Thu Jul 31, 2008 3:06 pm
 Location: Harrisburg, PA
Re: Math Help
The first thing I would note, to save time, is that when you're treating the scalar field as a solid object, none of the interior points matter for this calculation, since you'll never see them. All you care about (in the case of a cube) is the points lying on the six exterior faces. From there, the math comes down to two things: Which faces to draw and where to draw them.
Where to draw them
Rather than look at the problem as a moving observer and a stationary cube, I think it simplifies the math to look at it as a stationary observer and rotate the cube. If you center the sphere at (0,0,0) the location of the rotated points is simply the original location multiplied by the standard 3D rotation matrix with the three appropriate angles plugged in (each angle represents rotation about either the x,y or z axis). Then, you can simply draw the points at the calculated x/y location, ignoring the zcoordinate for plotting.
What if I have observer coordinates, not rotation angles?
To get the three angles from an arbitrary observer position, you'd need to convert the cartesian coordinates of the observer to spherical coordinates, which can be easily done with the appropriate formulas. It simplifies matters tremendously that since your observer can't "tilt their head", so to speak, the third angle (psi) will be zero for you. Or, more explicitly, for a given observer (x,y,z) location (angles are negative on purpose):
r = sqrt(x^2+y^2+z^2)
theta = acos(z/r) < General convention is that this angle is between 0 and 180 degrees, phi and psi are between 0 and 360.
phi = atan2(y,x) < Note that you need to use the 4quadrant atan2 function, not the 2quadrant one
psi = 0
Plug those three angles into the above matrix, multiply your original coordinates by it, and you'll have your final coordinates assuming your cube is centered on (0,0,0). Ignore zcoordinate for plotting a projection.
Which faces to draw
Now that you know where all the points on the faces are, you need to figure out which points to draw. If you were using solid faces rather than points, which faces to draw wouldn't matter (for a cube/rectangular prism) since you could simply draw the furthest ones away first, then draw the closer ones, which would cover up everything that should be hidden. With points, however, you'll need to have some way to figure out which face(s) are closest to you and then only draw the points on those faces. Theck's method works, but I can think of another way that might make more sense intuitively given a rotating cube centered at (0,0,0) with a stationary observer looking down the zaxis.
(assumption is that +x is to the right, +y is up, and +z is out of the monitor towards you)
1. Do the rotation described above.
2. Look at the coordinates for the center point on each face.
3. Only draw the points on faces with a center that has a positive (nonzero) zcoordinate. These will be the ones visible when looking down the zaxis.
If you had an even number of points (so there was no center one), then you could simply rotate the six points (0,0,1) (0,1,0) (1,0,0) (1,0,0) (0,1,0) (0,0,1) by multiplying them by the same 3D rotation matrix and draw the faces corresponding to those points that end up with a positive zcoordinate.
Where to draw them
Rather than look at the problem as a moving observer and a stationary cube, I think it simplifies the math to look at it as a stationary observer and rotate the cube. If you center the sphere at (0,0,0) the location of the rotated points is simply the original location multiplied by the standard 3D rotation matrix with the three appropriate angles plugged in (each angle represents rotation about either the x,y or z axis). Then, you can simply draw the points at the calculated x/y location, ignoring the zcoordinate for plotting.
What if I have observer coordinates, not rotation angles?
To get the three angles from an arbitrary observer position, you'd need to convert the cartesian coordinates of the observer to spherical coordinates, which can be easily done with the appropriate formulas. It simplifies matters tremendously that since your observer can't "tilt their head", so to speak, the third angle (psi) will be zero for you. Or, more explicitly, for a given observer (x,y,z) location (angles are negative on purpose):
r = sqrt(x^2+y^2+z^2)
theta = acos(z/r) < General convention is that this angle is between 0 and 180 degrees, phi and psi are between 0 and 360.
phi = atan2(y,x) < Note that you need to use the 4quadrant atan2 function, not the 2quadrant one
psi = 0
Plug those three angles into the above matrix, multiply your original coordinates by it, and you'll have your final coordinates assuming your cube is centered on (0,0,0). Ignore zcoordinate for plotting a projection.
Which faces to draw
Now that you know where all the points on the faces are, you need to figure out which points to draw. If you were using solid faces rather than points, which faces to draw wouldn't matter (for a cube/rectangular prism) since you could simply draw the furthest ones away first, then draw the closer ones, which would cover up everything that should be hidden. With points, however, you'll need to have some way to figure out which face(s) are closest to you and then only draw the points on those faces. Theck's method works, but I can think of another way that might make more sense intuitively given a rotating cube centered at (0,0,0) with a stationary observer looking down the zaxis.
(assumption is that +x is to the right, +y is up, and +z is out of the monitor towards you)
1. Do the rotation described above.
2. Look at the coordinates for the center point on each face.
3. Only draw the points on faces with a center that has a positive (nonzero) zcoordinate. These will be the ones visible when looking down the zaxis.
If you had an even number of points (so there was no center one), then you could simply rotate the six points (0,0,1) (0,1,0) (1,0,0) (1,0,0) (0,1,0) (0,0,1) by multiplying them by the same 3D rotation matrix and draw the faces corresponding to those points that end up with a positive zcoordinate.
Kimurellia  Holy/Protection Paladin  Scions of Destiny  EredarUS

Xenix  Posts: 244
 Joined: Thu Jun 25, 2009 4:56 am
Re: Math Help
Beat me to it.. Head explosion was my first thought when I saw "Math help"
"Warning: AA posts may cause severe urges to buy or rent games you may not have been interested in, known about or would normally consider playing. If you experience sudden urges to purchase said games please consult your wallet, bank account or significant other to see if these games are right for you and your budget."

Shyrtandros  Posts: 818
 Joined: Thu Dec 10, 2009 7:54 am
Re: Math Help
Thanks a lot guys, when I have time to take a more comprehensive look at those articles I should be able to create a solution.

Jeremoot  Posts: 434
 Joined: Tue Feb 08, 2011 5:36 pm
Re: Math Help
Xenix put down in math a lot of what popped into my head once I got what you were driving at. That said, you said the object being "viewed" isn't necessarily a cube, so you need a generalized solution rather then relying on various properties of a cube, yes?
Assuming the field doesn't have "holes" in it (i.e. areas through which the observer could "see" other parts of the field), I think you could use spherical coordinates to your advantage. Placing the center of the object at (0,0) with the observer on some axis (let's say Z), you can determine each point's proximity to the observer as well as its distance from the origin in the XY plane. If the model in my head is right (and someone please correct me if I'm wrong), then any point closer to the Z axis then a previous point (starting with the point(s) closest to the observer) should be hidden.
Of course, the thought model assumes symmetry about the Z axis. But it's slightly more general then a cube!
Assuming the field doesn't have "holes" in it (i.e. areas through which the observer could "see" other parts of the field), I think you could use spherical coordinates to your advantage. Placing the center of the object at (0,0) with the observer on some axis (let's say Z), you can determine each point's proximity to the observer as well as its distance from the origin in the XY plane. If the model in my head is right (and someone please correct me if I'm wrong), then any point closer to the Z axis then a previous point (starting with the point(s) closest to the observer) should be hidden.
Of course, the thought model assumes symmetry about the Z axis. But it's slightly more general then a cube!

Dazhbog  Posts: 700
 Joined: Thu Sep 13, 2007 10:17 am
 Location: Pig and Whistle Tavern
26 posts
• Page 2 of 2 • 1, 2
Who is online
Users browsing this forum: Yahoo [Bot] and 1 guest