# Math Help - Defining the quadrant of an angle within the equation

1. ## Defining the quadrant of an angle within the equation

So I have to scale down a triangle in space to have a preset hypotinuse (i.e. shrinking a line and keeping the angle).
initially I came up with (see case1.bmp).
but this only allows for triangles in northwest. so I came up with (see case2b.bmp) to output the point on bothe sides.
I have now hit the problem of if the moving point (Mx,My) has the same x value as the start point (Sx,Sy) then my method for picking the side becomes 0/0 which throws up errors everywhere.
Anyone have an alternative method of doing this or have an equation that if a<b=-1 and if a>b=1? (I don't care what happens when a=b (0/0) because cos(Theta) will be 0 anyway.)

2. ## Re: Defining the quadrant of an angle within the equation

Hi,
The attachment answers your problem. It shows the 4 possible locations of your angle theta, but the method indicated works regardless of the location of point M with respect to point S (the two points must be different).

3. ## Re: Defining the quadrant of an angle within the equation

Originally Posted by johng
Hi,
The attachment answers your problem. It shows the 4 possible locations of your angle theta, but the method indicated works regardless of the location of point M with respect to point S (the two points must be different).

that still has an if statement though.
maybe I am looking at this wrong.
What about determining the line Y=M*X+C that crosses (Mx,My) and (Sx,Sy) and calculating point P on that line?

4. ## Re: Defining the quadrant of an angle within the equation

Hi again,
I assumed that your question was a programming problem in my previous response. Here is Java code implementing what I said earlier:

Code:
  /* standardAngle computes and returns the angle from 0 to 2*pi of the
vector from (cx,cy) to (x1,y1).  However if the two points are the
same, a return of 0.
*/
private double standardAngle(double x1, double y1, double cx, double cy) {
double x, y, v, d;
x = x1 - cx;
y = y1 - cy;
d = Math.sqrt(x * x + y * y);
if (d == 0) {
return (-1);
}
v = Math.acos(x / d);
if (y < 0) {
v = 2 * Math.PI - v;
}
return (v);
}

// assuming the variables are defined:
double theta = standardAngle(mx, my, sx, sy);
it (theta != -1) {
px = sx + r * Math.cos(theta);
py = sy + r * Math.sin(theta);
}
else {
// some default action for the two points the same
}
Now as far as using the line from (sx,sy) to (mx,my) to intersect with the circle to find the desired point, yes, you can do it this way:

First handle the case where sx=mx (vertical line).

Otherwise, $m={my-sy\over mx-sx},\,\, d=-m(sx)+sy$

Next substitute into the equation of the circle $(x-sx)^2+(y-sy)^2=r^2$

to get the quadratic equation: $(m^2+1)x^2+(-2sx+2m(d-sy))x+(sx)^2+(d-sy)^2-r^2=0$

Use the quadratic formula to solve this last equation. By the nature of the problem, there will be two solutions, say x1 and x2. You can decide which is the desired value by:
if ((x1-sx)*(mx-sx) is positive)
px = x1 is the correct x value
else
px = x2 is the correct x value.
Once the correct x value is found, use the line equation to find the y value.

If you encode all of the above, you'll probably get at least as much code as what I gave at the beginning. One possible advantage of this approach is that no transcendental function calls are made. However, I have found the standardAngle function useful in other contexts.

5. ## Re: Defining the quadrant of an angle within the equation

Hi again,
It occurred to me that you might know about the parametric equation of a line. If you do, then the attachment shows yet a further solution to your problem:

6. ## Re: Defining the quadrant of an angle within the equation

Originally Posted by johng
Hi again,
It occurred to me that you might know about the parametric equation of a line. If you do, then the attachment shows yet a further solution to your problem:

Thanks I will try that.
this is not a programing problem but it is a problem I have to solve repeatedly so I am trying to set up a single equation in MathCAD where I can just change the inputs of Mx and My and take the outputs of Px and Py without having to check if Mx is greater than Sx etc