starfleetrp 127 Report post Posted March 25, 2006 Hi, I am having trouble getting a cordinate. I know what that angle, distance(pixels/unit), and starting cords(x,y) are but how would I find out what the other pair is. 0 degrees would be strait up. So pretty much what would be the formaula for this? Angle 330 (or 30) ?x,?y ___\___ Distance 30u/px ____\_ _____ 0,0 (ps ignore the underscores since it wont accept white spaces) 0 Share this post Link to post Share on other sites
jfclavette 1058 Report post Posted March 25, 2006 (x,y) |\ | \y| \ h | \ |___a\ x (0,0)We have h = 30.We have a = 30 degrees.sin a = y/hsin 30 = y/3030 * sin 30 = yy = 15You can calculate use the cos or use Pythagoreas theorem to find X.Also, click edit on my post to see how I formatted. HTHEdit: The backslash breaks the code and source tags 0 Share this post Link to post Share on other sites
NotAYakk 876 Report post Posted March 25, 2006 Wise man say:SOHCAHTOASin(x) = Opposite/HypotenuseCos(x) = Adjacent/HypotenuseTan(x) = Opposite/AdjacentYour angle describes a right-angle triangleAngle 330 (or 30)?x,?y_|_\___ Distance 30u/px_|__\__+---0,0Opposite = Hypotenuse * Sin(x)Adjacent = Hypotenuse * Cos(x)"Hypotenuse" refers to the length of the side opposite the right-angle corner of your right-angled triangle."Opposite" refers to the side opposite to the corner with the angle "x"."Adjacent" refers to the side adjacent to the corner with the angle "x".That help? 0 Share this post Link to post Share on other sites
starfleetrp 127 Report post Posted March 25, 2006 Am I doing this wrong because if I had an angle of 181 then shouldn't the Y axis be longer since its pretty much vertical so it should be arround 29 ish but its -.5ish. Unless 181 is pointing sideways. If it is (I think it is) then how would I convert it so 0/360/180 is at the top and not 90/270. Would I just have to change the angle by adding 90? Or is there a better way?BTW: Thanks for all of your replies, they were very helpful. I totally overlooked sine for some reason. 0 Share this post Link to post Share on other sites
philipptr 260 Report post Posted March 26, 2006 are you sure you're using degree and not radians?for example the math.h is using radians, to calculate degrees with a radians function do something like sin(deg*M_PI/180); maybe that helpsif you're shure this is right I would say its justCx=sin(angle)*Distance+StartX;Cy=cos(angle)*Distance+StartY; 0 Share this post Link to post Share on other sites
starfleetrp 127 Report post Posted March 26, 2006 I am having some trouble with this, my sprite should be turing is circles but it seems to be going in a wavy like patter, what could be wrong? Here is the code.... (with a bunch of junk) knts = 30.0f; turningForce = 16; //Turn by changing ships angle directionChange = ((knts / SCALE_FACTOR) * timeInterval * turningForce) / 15; direction = direction + directionChange; if (direction > 360) direction = direction - 360; if (direction < 0) direction = -(direction); //math.h uses radians so transfer our degrees to radians rAngle = sin(direction*M_PI/180); //Get the distance traveled velocity = (knts / SCALE_FACTOR) * timeInterval; //yChange = velocity; //Move along the path of our current angle //sin(angle)*Distance+StartX; yChange = sin(rAngle)*velocity; xChange = cos(rAngle)*velocity; yPos = yPos + yChange; xPos = xPos + xChange;EDIT: I just realized I made a mistake when I said I wanted 0 to be the the top, it should be facing the left.After a bit more searching I realized that 0,180 and 360 moves to the right, however 0 and 360 should be to the left and 180 to the right. The same would go for other directions. Would this be a simple fix, or would it require a lot more coding?Also a 90 degree angle seemd ot move at 135 or so (1/2 between top and right)[Edited by - starfleetrp on March 26, 2006 1:27:07 PM] 0 Share this post Link to post Share on other sites
philipptr 260 Report post Posted March 26, 2006 1. if you dont use direction somewhere else in your code you can remove the ifs, otherwise if its an integer you could do direction=(direction+360)%360;2. why are you using rAngle = sin(direction*M_PI/180); ??you convert a polar to rectangular coordinate, and then later in your code you're trying to convert it again? seems like what you wanted is rAngle = direction*M_PI/180;although I dont think that writing a variable and 2 times checking it is faster than 1 multiplication, so you could just convert it inside your sin/cos calls3. if you want to have it facing to the left why dont you just use sin((direction-90)*M_PI/180)*velocity? 0 Share this post Link to post Share on other sites
starfleetrp 127 Report post Posted March 26, 2006 Thank you, I totally overlooked the sin in #2And as for the number #1 I will do as you sugested and look into what the % means (since i've never used it...) 0 Share this post Link to post Share on other sites
philipptr 260 Report post Posted March 26, 2006 the % is the modulo, which gives you the remainder of a division. for example 10/4 gives you with integers a 2, but the actual number to be divided by 4 giving 2 is 8 so the difference between 10 and 8 is 2 -> modulo == 2if you do now %360 it will put all numbers above 360 in the range between 0 and 360 by subtracting 360 as often as needed. 0 Share this post Link to post Share on other sites