SRL Archive - Research & Development Lounge

RotateOriginConnection


n3ss3s

2008-01-21 10:47:19

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);
z := z + Radians(Degr);
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

2008-01-21 11:42:54

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

2008-01-21 11:58:33

Correct :)

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

bullzeye95

2008-01-21 12:20:28

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

2008-01-21 12:22:41

yea, the iAbs is unnecessary, as the square of any number is always positive.

nielsie95

2008-01-21 12:23:52

Or use Hypot ;)


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

n3ss3s

2008-01-21 12:31:32

Oopsie, I forgot that double - = + :)

Negaal

2008-01-21 13:46:08

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);
z := z + Radians(Degr);
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

2008-01-21 13:49:36

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

2008-01-21 13:50:35

converts to polar coordinates(is that the correct word?) then rotates then converts back to normal coordinates

nielsie95

2008-01-21 13:54:29

If anyone would describe what they are[Sin, Cos, Tan, Arc, Radian]…anything…


There's a tutorial about it.. ;)

n3ss3s

2008-01-21 14:07:23

Also, you should read this.. ;)

Negaal

2008-01-21 14:22:09

From: nielsie95
There's a tutorial about it.. ;)


I'v read it 2 or 3 times…