PDA

View Full Version : RotateOriginConnection

n3ss3s
01-21-2008, 03:47 PM
Rotates all the points of TPA from Origin by Degr degrees.

program New;

Procedure RotateOriginConnection(Degr: Integer; Origin: TPoint; Var TPA: TPointArray);
Var
I: Integer;
z, d: Extended;
Begin
For I := 0 To High(TPA) Do
Begin
z := ArcTan2(Origin.y - TPA[i].y, Origin.x - TPA[i].x) + Radians(180);
d := Sqrt(Sqr(iAbs(origin.x - TPA[i].x)) + Sqr(iAbs(origin.y - TPA[i].y)));
TPA[i].x := Origin.x + Round(d * Cos(z));
TPA[i].y := Origin.y + Round(d * Sin(z));
End;
End;

Var
TPA: TPointArray;
I: Integer;

begin
TPA := [Point(552, 50), Point(549, 61)];
RotateOriginConnection(90, Point(545, 57), TPA);
For I := 0 To High(TPA) Do
MoveMouse(TPA[i].x, TPA[i].y);
end.

King of Knives
01-21-2008, 04:42 PM
So if I have a TPointArray that contains all points from 0,0 to 4,4, would it rotate all those points? With some work this could be turned into "FindBitmapRotated", if it does what I think :D

-Knives

n3ss3s
01-21-2008, 04:58 PM
Correct :)

But 0,0 is a bad point, quadrants 2 and 3 wouldn't be visible.

bullzeye95
01-21-2008, 05:20 PM
Pretty cool :)
BTW, you should be able to change d := Sqrt(Sqr(iAbs(origin.x - TPA[i].x)) + Sqr(iAbs(origin.y - TPA[i].y)));
to
d := Sqrt(Sqr(origin.x - TPA[i].x) + Sqr(origin.y - TPA[i].y));

Markus
01-21-2008, 05:22 PM
yea, the iAbs is unnecessary, as the square of any number is always positive.

nielsie95
01-21-2008, 05:23 PM
Or use Hypot ;)

Hypot(origin.x - TPA[i].x, origin.y - TPA[i].y)

n3ss3s
01-21-2008, 05:31 PM
Oopsie, I forgot that double - = + :)

Negaal
01-21-2008, 06:46 PM
What the *uc*?
I can understand...mhhh...*I have to think good word to decribe it*...Nothing!
z := ArcTan2(Origin.y - TPA[i].y, Origin.x - TPA[i].x) + Radians(180);
d := Sqrt(Sqr(iAbs(origin.x - TPA[i].x)) + Sqr(iAbs(origin.y - TPA[i].y)));
TPA[i].x := Origin.x + Round(d * Cos(z));
TPA[i].y := Origin.y + Round(d * Sin(z));

What the...?
Shit hits the van...

Since I don't know what are Sin Cos Tan etc... Arc?!

I should have learned it like...woah...2 years ago when I was in 8th grade...
Well, I got test 5 ^^
I cribed that...
I got exam almost 4...
There were choice exercises...I choosed opposite of Sin - Cos - Tan part....

Now we're studing some radians...and the 360 system...I'm good there at 360 system*RadialWalk FTW!*, I still don't know radians but I remeber that they are same as 360 system, only smaller values...

Once again: What the *uuuc*?

If anyone would describe what they are[Sin, Cos, Tan, Arc, Radian]...anything...
Btw!:D I know what iAbs does!:D:p

Nice job though, since it's so l33t I can't understand it...

n3ss3s
01-21-2008, 06:49 PM
Sin = b/c
Cos = a/c
Tan = b/a
Arc[trigfunctionhere] is the inverse of the function, wizzup explained it to me many times like this:

ArcSin(Sin(x)) = x

and I was like whats that got to do with anything, but now I understand.

The best explanation I can do:

ArcTan returns the angle the tangent was done to :p

EDIT: By the way...
I should have learned it like...woah...2 years ago when I was in 8th grade... I'm on 7th grade :p

Killerdou
01-21-2008, 06:50 PM
converts to polar coordinates(is that the correct word?) then rotates then converts back to normal coordinates

nielsie95
01-21-2008, 06:54 PM
If anyone would describe what they are[Sin, Cos, Tan, Arc, Radian]...anything...