Missing coordinates. Basic trigonometry help

refer to my quick chart below.

what I'm trying to do is get the coordinates of the yellow dots using the angle from the known coordinates of the red dots. Assuming each yellow dot is approximately 20 pixels from x: 50 / y: 250 the red dot is at right angles (I think that what she called), how can I get their coordinates?

I believe that this is a very simple trigonometry, and I should use Math.tan (), but they did not teach us mathematics in the art school.

alt text http://www.freeimagehosting.net/uploads/e8c848a357.jpg

+7
math trigonometry coordinates
source share
5 answers

In fact, you do not need triggers for this. Just use slopes or change the values ​​in x and y .

For the slope line m = y/x line perpendicular to this line has a slope of -1/m or -x/y .

The slope of m between the red dots is -150/150 or -1/1 . I noticed that your positive y points down.

Therefore, the positive slope is 1/1 . Both of your x and y change at the same speed with the same amount.

Once you know this, then everything should be pretty easy to understand. Since they are aligned at an angle of 45 degrees, the aspect ratio of the triangle 45-45-90 is 1 : 1 : sqrt(2) . Therefore, if your length is 20 , the individual change in x and y will be 20/sqrt(2) or roughly 14 in integers.

So, your two yellow dots will be at (36, 236) and (64, 264) . If the lines are not aligned to a convenient degree, you will need to use arctan() or something similar, and get the angle between the line and the horizontal line so that you can determine the ratio of x and y changes.

I hope my answer was not too difficult to follow. For a more general solution, see Troubadour's answer.


Edit: Since the OP says that the bottom red dot actually rotates around the top red dot, we need a more flexible solution.

I am going to extend this answer from Troubadour since I am doing the same. Please refer to his message when you read mine.

1. Get the vector from the source (200, 100) to the rotating point (50, 250):

 vector = (200 - 50, 100 - 250) = (150, -150) 

2. Rotate the vector, replacing x and y and negate x to get a new vector:

 vector = (150, -150) => swap => (-150, 150) => negate x => (150, 150) 

3. Get the unit vector (length 1) from the new vector:

 vector = vector / length(vector) = (150 / length(vector), 150 / length(vector)) ~= (0.7071, 0.7071) where length(vector) = sqrt(150^2 + 150^2) ~= 212.2320 

4. Get a displacement vector of length 20 by multiplying the unit vector.

 displacement_vector = vector * 20 = (0.7071 * 20, 0.7071 * 20) = (14.1421, 14.1421) 

5. Add / subtract this vector to / from your rotating vector (point):

 yellow_1 = (50, 250) + (14.1421, 14.1421) ~= (64, 254) yellow_2 = (50, 250) - (14.1421, 14.1421) ~= (36, 236) 

I hope that the above steps will help you formulate your code. It doesn't matter what its angle is, the same steps.

+7
source share

What is the red dot at (50, 250) A and at (200, 100) B.

One way would be to first compute the vector AB ie

 v_AB = ( 200 - 50, 100 - 250 ) = ( 150, -150 ) 

You can generate a vector at right angles to it by replacing the components and changing the sign of one of the two components. So

 v_AB_perp = ( 150, 150 ) 

is a vector rotated by rotating v_AB clockwise when you look at it on the screen. You can normalize this to get a unit vector by dividing it by ie

 v_AB_perp_normalised = v_AB_perp / |v_AB_perp| 

To get the yellow dots, just multiply this by 20 pixels and add / subtract it by the coordinates of A.

+4
source share

Since the yellow dots are at a right angle from the red-red line, you can use something simpler. I will not answer the whole question, but I will try to give a few tips:

Ignoring the actual distance to the yellow dots, imagine some other points on the same NW-SE line, at the same distance as the red NE. The vector for this is simply a vector to the red dot, rotated 90 degrees.

A rotation of 90 degrees can be performed by changing the coordinates and inverting one of them.

As soon as you do this, move this yellow dot to its closer position, scaling this vector at a real distance (20).

+2
source share

This should work (I’ll just refer to the leftmost yellow dot, but we will get the coordinates of both at the end):

  • Find the slope of the line given by the two red dots.
  • Find the equation of the line between the yellow dot and the red dot (d2).
  • Find the coordinates of the yellow dots using the linear equation d2 and the fact that the distance from the bottom red dot is 20.

For 1 :

Find the slope: m = (y1 - y2) / (x1 - x2) = (250 - 100) / (50 - 200) = 150 / -150 = -1

For 2 :

We know that d1 (the line between the red dots) is perpendicular to d2 (the line between the red dot and the yellow dot), so the product of their slopes should be -1 . Therefore, the slope d2 is m = 1

Therefore, the equation is: d2: y - 250 = x - 50 => d2: y - x = 200

For 3 :

The desired yellow dot lies on the d2 line, and its distance to the lowest red dot is 20 . Solve the system of equations:

 y - x = 200 (x - 50)^2 + (y - 250)^2 = 400 

The calculation becomes pretty ugly, but its solution with math gives:

{{x -> 35.8579, y -> 235.858}, {x -> 64.1421, y -> 264.142}}

Where your two yellow dots lie!

Programmatically, you can easily solve such a system by replacing y = 200 + x in the second equation, then moving everything on one side and resolving it as a quadratic equation.

+2
source share

It is quite easy if you know that it will remain at 45 degrees. If the distance from 50, 250 is 20, then the points are at (50 - (20*sqrt(2)), 250 - (20*sqrt(2))) and (50 + (20/sqrt(2)), 250 + (20/sqrt(2))) .

Typically, the 20*sqrt(2) each should be replaced by (distance)*cos(angle) and distance*sin(angle) . One for the x coordinate and one for the y coordinate. (depending on which side you are measuring the angle from!)

So you should use sin and cos. 45 degrees is a special case when sin and cos are both 1/sqrt(2) , so it doesn't matter which direction you use them.

+1
source share

All Articles