• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to move and reverce a geometric object?  RSS feed

 
Moud Elma
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,

this is my first participation here, I am happy because I found such a great forum and I hope you could help me.
I am new to the Java world. I created a class GeometricObject and I implemented some methods on it to draw objects, now
I want to implement other methods to move and reverse these objects:

move() :let the object make a step forward, and reverse()
reverse() : turn round the direction of the movement

I used a class Vertex to create points in 2 dim (x,y)

here is the class Vertex:



here is the class GeometricObject :




I think of using the method addself() (in Vertex) to move the object foreward but I dont know how to implement it, any Ideas please?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please UseCodeTags when posting code or configuration. Unformatted code and configuration is unnecessarily difficult to read.

Seems like you already know what you want to do--are you having a specific problem?
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch. Please UseCodeTags when you post source code (I added them for you in your post above).
 
Moud Elma
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all I will use the tags for my codes,

so I can use addself() to move the object forward, but how can I implement the method reverse() to turn round the direction of movement of the object.

Moudy
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Probably the same way, but subtract instead of add? Or if you're keeping a heading, flip it 180 degrees (or pi radians if that's how you swing).

I'm not a big fan of the method names subself, multself, etc... they seem redundant, and even if they weren't, they're a little hard to read without following the subSelf etc. naming convention. But subSelf doesn't make sense to me--my impression would be that you'd be subtracting the same instance, not subtracting something else. I'd much prefer subtract(Vertex) and multiply(Vertex) or something. Just an idea :)
 
Moud Elma
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks you, so this is my implementation for the move method



I am not sure if it works but I created the method scalarMultiplay() and gave -1 as parameter to change the direction





 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!