Avatar billede fredand Forsker
30. april 2003 - 15:55 Der er 3 kommentarer og
1 løsning

Need help to calculate a cordinate!

Hello!

I have a app that should move a image around on the screen. But the problem is that I do not know how to calculate a new cordinate upon some certain criterias. The criteras that is given is:

Cordinate x1, y1 for eg (40,110)
The length that the image should move (a radie) for eg 25
The angle in what direction the image should move.

I have made a image that perhaps explaine this better at:
http://medlem.spray.se/fredand44/kordinat.gif

So the question is upon the given critera how do I calculate the next cordinate (x2,y2)?

Best Regards
Fredrik

Ps the language I use is Java, but I do not think that that matters.
Avatar billede arne_v Ekspert
30. april 2003 - 16:03 #1
x2 = x1 + cos(angle) * distance
y2 = y1 + sin(angle) * distance
Avatar billede arne_v Ekspert
30. april 2003 - 16:04 #2
(be aware that most cos and sin function expect radian not degree as input)
Avatar billede soreno Praktikant
30. april 2003 - 18:09 #3
If it's something you are going to spend lots of time developing, I would recomend you investigate in Graphics2D.

Graphics2D can perform transformations (scale, rotate, translation). However Graphics2D is not something you learn in 10 minutes.. :-)

http://java.sun.com/docs/books/tutorial/2d/index.html
Avatar billede fredand Forsker
05. maj 2003 - 12:43 #4
Thanx!

Fredrik
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester

IT-JOB