News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Trigonometry question

Started by Glenn9999, January 19, 2011, 04:55:55 AM

Previous topic - Next topic

Glenn9999

This does have something to do with a assembler programming project I had in mind, but need to get it past the design stage and I don't remember my trigonometry classes well enough to remember how to solve this.  So I need a jump in the right direction.

The problem I have involves finding a point on a circle that is X degrees away from a known point.  I know the point on the surface of the circle, the center point, and consequently the radius of the circle.  What is the math that is needed to find this point?

For example, center is (3, 5), point on circle is (10, 12).   What are the coordinates of a point that is 40 degrees (keeping it simple, I know radians need to be involved) away from the given circle point?

TmX

Sorry if the pic is a bit unclear...



For the sake of simplicity, the center of the circle is (0,0).
First we got point A. The angle is calculated by this equation:

(YA and XA are the oordinate and absis of A).

Then we rotate degrees. The result is point B.
How can we get the absis & ordinate of B?
Absis:


Ordinate:


FORTRANS

#2
Hi,

   Use homogeneous coordinates and matrices.  Form a
translation matrix to put the center of the circle onto the origin.
Then make a rotation matrix to rotate your point.  Then
use another translation matrix to move the circle's center
back to where it should be.  The following should have a
sanity check as it is from memory, but should be close.

Regards,

Steve N.

Edit:

Fixed the point to a vector.

Edit2:

You probably neet to transpose the translate matrices for
use with column vectors.


   X, Y are the coordinates of the circle's center.
   Px, Py are the coordinates of the point on the circle.
   S, C are the sine and cosine of the angle.

   | Px |
   | Py |        Homogeneous point.
   |  1 |

   |  1  0  0 |
   |  0  1  0 |  Translation to origin.
   | -X -Y  1 |

   |  C -S  0 |
   |  S  C  0 |  Rotation matrix.
   |  0  0  1 |

   |  1  0  0 |
   |  0  1  0 |  Translation back to center of original circle.
   |  X  Y  1 |

   Then something like:  (Depends on notation...)

   Result = Tran2 * Rot * Tran1 * Point

FORTRANS

Hi,

   Okay, I checked and the above seems to follow Blinn's
notation, except that the point should be a vector rather
than a matrix.  Foley and Van Dam show things a bit
differently.  So here is their version.

Regards,

Steve


   X, Y are the coordinates of the circle's center.
   Px, Py are the coordinates of the point on the circle.
   S, C are the sine and cosine of the angle.

   | Px Py  1 |  Homogeneous point.

   |  1  0  0 |
   |  0  1  0 |  Translation to origin.
   | -X -Y  1 |

   |  C  S  0 |
   | -S  C  0 |  Rotation matrix.
   |  0  0  1 |

   |  1  0  0 |
   |  0  1  0 |  Translation back to center of original circle.
   |  X  Y  1 |

   | Rx Ry  1 |  Result.

   Then:

   Result = Point * Tran1 * Rot * Tran2

raymond

One important detail to remember.

You will most probably want to use the FPU to compute the original angle from its tangent. It can only return the angle in two of the four quadrants. You must adjust this angle "manually" for the other two quadrants based on the data used to compute that angle.

For example, using the data given in your original post, the tangent of the initial angle would be:
(12-5)/(10-3) = 7/7 = +1.0000
If your point on the circle would have been (-4,-2) instead of (10,12), the tangent of that angle would be:
(-2-5)/(-4-3) = -7/-7 = +1.0000, which would result in the same angle as above although it is 180o opposite.
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com

Sarel

You need to set the center of your cirle on the center of the graph paper. You do this by subtracting (3;5) from your center point (3;5) and point (10;12) on the circle . This wil give you new points to work from (0;0) and (7;9). Then you can use Tan() function to change from Rectangular format to Angular format. From there you add the 40 degree angle to the angle you found with Tan(alpha)= y/x. Now you must convert back to Rectangular format with Sin() and Cos(). Lastly you must add (3;5) to your points. This will be a nice program to get introduced to the math co-processor. (You definately need the floating point math for acuracy)

Sarel

Your new point is (7;7) not (7;9) sorry for the typimg error. Have Fun

vanjast

In simple terms, which is what the matrix operations reduce to :

You can skip the translation to the origin,
Calculate the radius via pythagoras and original angle (FPU sin,cos,tan)
Add 40 degrees (converted to radians) to the original angle
Find new cords adding the origin points (translation).

:8)

Glenn9999

Thanks for the help.  My mind never quite registered math-geek speak very well through my math classes (to Calc II) and that was all I was finding online if I found anything.  I guess part of why programming is attractive to me is that my mind ends up needing a process in order to understand such things.

Quote from: Sarel on January 21, 2011, 10:43:23 AM
This will be a nice program to get introduced to the math co-processor. (You definately need the floating point math for acuracy)

Yes I figured it would be.  I've been trying to fit in programs that I'm already doing in another language to ASM learning (this one involves rotating bitmaps), simply because they look like they would be rigorous enough and interesting enough to do the learning (like the MD5 & SHA1 hash stuff was for basic ASM stuff).  Strings will probably be a silly-function type thing because I really haven't come across anything for it yet that is both functional and rigorous enough.

Probably the big thing will be to get a good enough reference (not instruction manual, not textbook) for ASM that can help my mind along on how the instructions work.