Razor89 Posted August 20, 2005 Posted August 20, 2005 If I have two coordinates for a line, the begining and the end, how do I find what angle the line is pointing relative to the begining of the line? I need this for a upcoming project where I need to move the camera in a 2D world and it has to follow a line thus I need to know the angle which the camera needs to move at. Thanks! Quote
Joe Mamma Posted August 20, 2005 Posted August 20, 2005 If I have two coordinates for a line, the begining and the end, how do I find what angle the line is pointing relative to the begining of the line? I need this for a upcoming project where I need to move the camera in a 2D world and it has to follow a line thus I need to know the angle which the camera needs to move at. Thanks! tan θ = (Y2-Y1) / (X2-X1) θ = arctan((Y2-Y1) / (X2-X1)) Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
Razor89 Posted August 20, 2005 Author Posted August 20, 2005 I think I might be able to work with that weird looking formula but do you have any code by any chance? Quote
Joe Mamma Posted August 20, 2005 Posted August 20, 2005 I think I might be able to work with that weird looking formula but do you have any code by any chance?Oh it is sad that simple trigonometry is 'weird' look up Math.Atan Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
Razor89 Posted August 20, 2005 Author Posted August 20, 2005 Dim lineAngle as Single = tan(arc((Y2-Y1) / (X2-X1))) or Dim lineAngle as Single = Math.Atan((Y2-Y1) / (X2-X1)) Is that correct? Quote
Joe Mamma Posted August 20, 2005 Posted August 20, 2005 Dim lineAngle as Single = tan(arc((Y2-Y1) / (X2-X1))) Is that correct?nope. . . Dim lineAngle as Double = Math.Atan((Y2-Y1) / (X2-X1)) Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
Razor89 Posted August 20, 2005 Author Posted August 20, 2005 Ok, thanks, I'm not good with math and I haven't made my way to algebra yet so please bare with me :) Quote
Joe Mamma Posted August 20, 2005 Posted August 20, 2005 NOTE THAT ATAN IS A DOUBLE!!!! Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
Joe Mamma Posted August 20, 2005 Posted August 20, 2005 or Dim lineAngle as Double = Math.Atan2(Y2-Y1,X2-X1) Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
Razor89 Posted August 20, 2005 Author Posted August 20, 2005 Ok, another thing is, does this return in degrees or radians? I assume radians. Quote
Joe Mamma Posted August 20, 2005 Posted August 20, 2005 look up Math.ATan - complete example Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.