Please help me with this mathematic issue

Anyone can help me with this:

[SIZE=1] -Assuming that we have a rectangle (100x100px) at [x:0 y:0]
-Then we point the mouse to the right side (for example, at [x:100 y:80])
-Then we’ll have a point (B) [x:0 y:80] which is perpendicular to (A) point
-Then we rotate the rectangle to n degrees (30 degrees in this example)
-We still point the mouse to the right side (A)…
-Then how to get the coordinates of point (B) that perpendicular to (A) point?[/SIZE]

hi, I’m back again with this issue. Now I found that your code doesn’t really correct as required.
See it here:
http://img66.imageshack.us/my.php?image=answerae9.swf
You can see that the red point doesn’t be at the right position, how can I fix this? :expressionless:

Hm… where did you wanted it to be? Meaning, which corner of rectangle it should point to?

This problem sounds suspiciously like someone’s homework :wink:

A problem similar to this was posted a couple days ago. Someone suggested using the Matrix class and applying a transform which I would agree too. But this does look like your homework… So they probably want you to know the math behind it…

no it’s not a homework mates, I want to calculate the ‘real’ distance between 2 points in a rotated rectangle.
@wvxvw: I want the red dot must be on the other edge of the rectangle (like in the example image shows at the first post). In your code the red dot is on the circle…

But you dont rotate the rectange, and you do rotate the dot… so how do you want the dot to follow the rectangle’s adge/corner… or, meaning, if the rectangle doesn’t rotate, than it should allways stay in the same place… me confused =|
OK, say, the corners of the recatangular are A,B,C,D counting from top-left (A == the one that doesn’t move), than, (assuming you’re using my example) which corner position you need to know?

[quote=bonnieraymond;2341597]no it’s not a homework mates, I want to calculate the ‘real’ distance between 2 points in a rotated rectangle.
@wvxvw: I want the red dot must be on the other edge of the rectangle (like in the example image shows at the first post). In your code the red dot is on the circle…[/quote]

You say here that you want the distance between the two points. That distance is 100: 100 in the x direction and 0 in the y direction, in the unrotated square. Since the dots remain fixed with respect to each other, their distance apart remains the same regardless of the rotation of the square. Just like if you’re driving and your friend is in the passenger seat. You’ll still be in the driver’s seat and your friend will still be in the passenger seat if the car turns a corner, so the distance between you doesn’t change as the car rotates.

However, your original problem statement didn’t say you want the distance between the two points. It says you want “the coordinates of point (B) that perpendicular to (A) point.” Unfortunately “B perpendicular to A” has no meaning because two POINTS are never perpendicular to each other. Only two lines or two planes can be perpendicular to each other.

Perhaps you’re asking what the coordinates of B would be when you rotate the square. This can easily be answered without even considering point A, since you know the original coordinates of point B. The new coordinates of point B after rotating the square 30 degrees are:

x = -40
y = -69.3

I’ve illustrated how to do this by doctoring your diagram, attached. You’ll recognize the cos and sin functions from wvxvw’s post. I did not go through wvxvw’s post in detail, but I believe the reason he speaks of a CIRCLE instead of a SQUARE is because, as I alluded to, the ANGLE of rotation of the line your point B lies on is all that requires consideration to determine B’s new position – not the shape B lies on. Despite your visualization of a SQUARE, the rotation of the square sweeps B through the arc of a CIRCLE.

What ARE perpendicular are the line from (0,0) to B, and the line from B to A. Of course, since B and A are fixed with respect to each other, those two lines will remain perpendicular as the square rotates. So, if you are also possibly wondering what the coordinates of A are after rotation of the square, you can find them in a similar fashion as above.