You are not logged in.
This method is fine as far as it goes but has certain obvious drawbacks, it requires the observer be looking paralell to the Z axis. Fortunatly I have developed a function allowing you to rotate your view, which I'll explan shortly.
Ok, what we want to do basicly in a 3d engine is convert 3d, to 2d. We are creating an illusion to graph 3d objects on a 2d plane (a computer or tv screen) so that they appear to be three dimensional even though its being displayed on a flat surface.
A computer screen is supposed to be like a window to a world. If you were to look through a window at a box, the image of the box would be passing through the window at a certain point and entering your eyes. If you were to replace the window with a board and draw the box at the exact same place where the original box passed through the glass, it would look just like the real box through the window.
The first pic below illustrates this. If your standing behind a window, looking at a box. And you look at corner C, you are looking through a specific point on the glass. The point where the redline I drew, thats drawn from your eyes to the box, crosses through the window. If you were to draw corner C at that point on the window, and draw all the corners where they intersect the glass, and connect the points with lines. You would see a 3d image of the box exactly as you saw it through the glass.
A computer screen is just like a window to another world so we can do the same to graph 3d points, only it must be done mathematically. First I placed the viewer on an X,Z plane at 0,0. And placed a 2 by 2 box 10 units in front of the viewer. I then placed a small "screen" in front of the viewer. We want to know exactly where every point intersects that screen to graph it.
First we draw a line from the viewer to a point (we'll use point C) Then a line from the viewers location, straight forward, and finally, a line that passes through point C that is paralell to the computer screen or window. We know have two similar triangles. On the big triangle, the horizontal piece is the horizontal distance from the viewer to the point. On the small triangle, this corresponding side is the distance from the center of the computer screen to the point where point C will be placed. Since the triangles are similar all we have to do is scale the parts. We will make the vertical length of the small triangle 100 units. (100 will most likely be bigger number even though its drawn smaller but it still works). We then have to find the scale factor of the big triangle to the small triagnle. First we find the Z distance to the object by subtracting the viewers Z coordinate from the objects Z coordinate. The distance in this case will be 10 since I set the point 10 units out. So now we have corresponding side lengths so we can find the scale factor. 100 * scalefactor = 10. scalefactor = 0.1. We can now use this scale factor to find the horizontal side of the small triangle. We find the x distance from viewer to object by subtracting the viewers x from the objects x. We then multiply by the scale factor to get the length of the small triangle and the location on the computer screen.
This only gave us the new x coordinates. You also need to do the same thing on the Y,Z plane to find the new height as well, but its the same process so I don't think we need to go through it.
The first pic below is an illustration of what we're doing.
The bottom pic shows using the system with the x,y,z coordinates of a 2 by 2 box 10 units away, translated and graphed using this system. (except I scaled the distances in relation to 200 instead of 100 to make it easier to graph.
results:
First we find the perpendicular distance to the object from the viewer, by finding the z distance between them. We subtract the objects
I've just finished trig and moving onto calculus. I've only learned a little C++ but for practice I decided to write my own program for practice in math and programming.
I have not been taught how a 3d engine works, mathematically. I found this explanation here http://en.wikipedia.org/wiki/3D_projection but I guess I'm not quite at the level needed to understand it. So I decided to see if I could figure out my own. Basicly I'm reinventing the wheel trying to figure things out myself, for the fun of it, to see how smart I am. lol. My engine is not even close to a real 3d engine yet since all it does is translate mathematical points based on distance, angle, etc. I'll try to post some step by step pics of how the program works.
Things are going well. I just ignored the slight inaccuracies. I already tried writing pi to a lot more decimal places but that just ended up writing really small numbers in scientific notation when it should have been zero.
But in the end, it seemed the inaccuaracies were small enough not to be detrimental to the program.
Grrr.... well it seems theres also some slight inacuracy with sin(x) at some angles as well. Phoey!
What I need is a way to round a number to 4, or 5 decimal places.
It would be much easier (and clearer) to just pass in points as arguements, rather then having to individually pass in horizontal and vertical coordinates. But then I'd have to define a new function for every plane. xy, xz, yz. I wonder if it would be worth it...
It works!
Well I guess I could just take the sine of the complement angle since thats what cosine means and the sine function appears to be working fine. (I call this sort of thing "humoring the computer")
Darn it! Cos(x) is messing up and giving me a very small decimal number for the cosine of 90 instead of 0. ( and no I didn't forget to convert to radians)
Great minds think alike. But I have my reasons. I already have a class "point" with x,y,z member data. But this polar angle function is going to be used not just on the x,y plane. Its going to be used on x,z plane, a y,z plane, as well as the x,y plane. So if I use x and y, in somecases I'd have to use y, for x, instead of y, for y. The same reason why I didn't pass in "points" as arguements. Because sometimes I'll be using only their y,z coordinates, other times their x,z coordinates, etc. There is probably a simple way to do it with points but I haven't thought of one yet.
I'm writing a math program to calculate the location of a point (on an x,y plane) based on its x,y, z coordinates, the observers x,y,z coordinates, and the angle at which he's looking. Basicly I'm reinventing the 3d engine myself, trying to figure things out on my own. I've heard real 3d engines just use matrices but my system seems to work anyways.
Your object and origin suggestions are good, the only reason I didn't pic "origin" is because that usually means 0,0,0.
I'm going to write a function for the distance formula to find the directed distance from the center point, to the object, then I can write a function that calls these two express any points coordinates in referance in polar form only in relation to any center point you chose, rather then just the origin. The primary purpose of this will be used to rotate a point around an axis (the center) by first converting to polar form, adding or subtracting the angle of rotation, then converting back to rectangular from to get the new coordinates of the point.
I really need to rename the parameters... :-/
This function is to find the polar angle from "cent" (a center point) and obj (an object) Typically when we write something in polarform we begin from the origin (0,0) but this allows you to speficy the origin. First it finds the horizontal distance from the center to the object and then finds the vertical distance. The vertical distance is divided by the horizontal distance to find the tangent. Then atan() is used (arctangent) to find the angle to which the tangent belongs (but atan returns the value in radians so I converted it). I used a few "if" statements first to return 270 or 90 when the adjacent is zero, to avoid division by zero, and also when oposite and adjacent are both zero, (which means the points overlap and there is no angle relation).
I just don't like using a whole mess of "if" statements, and I want to make the function as simple, short, and direct as possible. Take a look at the function, tell me what you think of it, and tell me if you think it can be simplified or if some steps are redundant.
float polarangle(float centh, float centv, float objh, float objv)
{float h, v, r;
v = objv - centv; // finding vertical distance from centv, to objvh = objh - centh; //finding horrizontal distance from centh, to objh
if ((h == 0) && (v < 0)) { return 270;} // avoid division by zero
if ((h == 0) && (v > 0)) { return 90; } // avoid division by zero
if ((h == 0) && (v == 0)) { return 0; } // points overlap, no angler = atan(v/h) * 180/3.14159; //calling arctan and converting radians to degree's
if (h < 0) { return (r + 180);}
return r;
}
Hey it works! Thanks again mathisfun! Are there functions for arcsin, arccos, and arctan?
wow, sometimes please does work!
Thats exactly what I'm looking for! :-D Thanks a yotta, Mathisfun!
please?
I'm writing some awsome programs using math but I really really really need access to sine, cosine and tangent functions, also I really could use arcsin, arccos, and arctan, but arctangent the most since I need to convert from rectangular form to polar form and back.
Someone gave me a link to the formulas for sine, cosine and tangent, which was great and they appear to work, but they call a lot of factorials and very large numbers "270^5" :-O
If anyone knows where I can get a copy of the source code for functions for sine, cosine, tangent, arcsine, etc. so I can just copy the definition into my program and call on it when I need it. It would be a MAJOR help!
Doulbe angle identities are created by using the sum identiy's where both angles are the same. So instead of "sin(A+B)" you use "sin(B+B)" or 2b: Double the angle. You then replace B everywhere with A.
I have a page I copied out of the back of my mathbook that has most of the common identities listed. You definitly need to write them down for referance. You begin to remember them after using them long enough.
??? e as in the natural logarithm?
I saw on numb3rs yesterday that the irrational number "pi" is found in other area's of math, totally unrelated to circles. Is this true? And where else does pi appear?
Thanks, man. :-)
To restate what I just said in a slighty more organized form:
I think these excersizes are meant to teach you understand how the functions work, I understand why the curve is the way it is given a particular point, but I find I can't sketch it accurately without inserting values into the equation. But if I just try to sketch it generally, then I pretty much need to ignore whats happening and just sketch the pattern, which teaches me little.
Sketching sine and cosine curves are relatively easy. You just need the vertical translation, the magnitude, the period, and the horizontal translation.
Sketching tangent curves are slightly more difficult.
But when it comes to sketching the arc forms of trigonometric functions, I don't really know what to do. I could just study the patern that develops with each one, but that teaches me little. I could plot the points one by one in a few spots by just inserting values into the function, but I think this is cheating. I'm not really sure what else I'm supposed to do.
I guess [sup] 2 [/sup] doesn't work here. :-(
Hmm... x[sup]2[\sup]