Results 1 to 8 of 8
Thread: Points in a line
 07032012, 03:02 AM #1Member
 Join Date
 Jul 2012
 Posts
 27
 Rep Power
 0
Points in a line
Hello fellow programmers,
I am trying to create a game where you can put down elements like dirt and water (that's all I have yet I started yesterday) and it comes down as dots and they fall on each other and react differently.
much like this [Moderator edit: irrelevant link removed]
you use the mouse to place elements but it separates the dots when you make a large line of them. I know if I make a bunch of dots in between the two points I can make a line that is not separated. heres a picture:
do you guys know a way of finding all the points of any line from point A to point B? Code examples appreciated.Last edited by DarrylBurke; 07032012 at 05:23 AM.
 07032012, 03:21 AM #2Moderator
 Join Date
 Feb 2009
 Location
 New Zealand
 Posts
 4,565
 Rep Power
 12
Re: Points in a line
a way of finding all the points of any line from point A to point B?
 07032012, 03:30 AM #3Member
 Join Date
 Jul 2012
 Posts
 27
 Rep Power
 0
Re: Points in a line
Yes this helps, all I need is it to make it not "gappy" for the x.
 07032012, 04:29 AM #4Member
 Join Date
 Jul 2012
 Posts
 27
 Rep Power
 0
Re: Points in a line
I added this to it but It gives me strange results...
Java Code:if(mouseType!=0){ int dx= mouseLast.xmousePos.x; int dy= mouseLast.ymousePos.y; if(dx>0){ for(int i=0;i<dx;i++){ makeSpeck(new Point(mouseLast.x+i,mouseLast.y+i*(dy/dx)),mouseType1); } } else if(dx<0){ for(int i=0;i>dx;i){ makeSpeck(new Point(mouseLast.x+i,mouseLast.y+i*(dy/dx)),mouseType1); } } else makeSpeck(new Point(mousePos.x,mousePos.y),mouseType1); }
I don't know why. any suggestions?
 07032012, 04:32 AM #5Senior Member
 Join Date
 May 2010
 Posts
 436
 Rep Power
 4
Re: Points in a line
It would probably help you and us if you simplified your problem to its most basic form by creating a minimal compilable and runnable example, one without any background images or function at all except for drawing the dotted line or whatever your goal is, and then posting this attempt here. This way we can all work with your workable code, it won't be so large as to completely overwhelm us, and perhaps we can find a way to get it to work. What I'm asking for is an SSCCE. Please check the link for all the details regarding this useful construct.
 07032012, 05:07 AM #6Member
 Join Date
 Jul 2012
 Posts
 27
 Rep Power
 0
Re: Points in a line
I made a simple version of what I want to make. Though it is not graphic, it still does the thing.
Java Code:import java.lang.Math.*; import java.awt.*; public class lineTest { public static void main(String[] args){ Point p1=new Point(Integer.parseInt(args[0]),Integer.parseInt(args[1])); Point p2=new Point(Integer.parseInt(args[2]),Integer.parseInt(args[3])); System.out.println("line from ("+p1.x+","+p1.y+") to ("+p2.x+","+p2.y+") has points:"); int dx= p1.xp2.x; int dy= p1.yp2.y; if(dx>0){ for(int i=0;i<=dx;i++){ System.out.println("("+(p2.x+i)+","+(p2.y+i*dy/dx)+")"); } } else if(dx<0){ for(int i=0;i>=dx;i){ System.out.println("("+(p2.x+i)+","+(p2.y+i*dy/dx)+")"); } } else System.out.println("("+p1.x+","+p1.y+")"); } }
kyle@kyleDellDM061:~/Documents/javaPrograms/MyStuff/dotWorld$ java lineTest 0 0 20 3
line from (0,0) to (20,3) has points:
(20,3)
(19,3)
(18,3)
(17,3)
(16,3)
(15,3)
(14,3)
(13,2)
(12,2)
(11,2)
(10,2)
(9,2)
(8,2)
(7,2)
(6,1)
(5,1)
(4,1)
(3,1)
(2,1)
(1,1)
(0,0)
kyle@kyleDellDM061:~/Documents/javaPrograms/MyStuff/dotWorld$
the problem is it works...
 07032012, 05:09 AM #7Member
 Join Date
 Jul 2012
 Posts
 27
 Rep Power
 0
Re: Points in a line
the site is not loading btw
 07032012, 04:29 PM #8Member
 Join Date
 Jul 2012
 Posts
 27
 Rep Power
 0
Similar Threads

Open a URL and read it line by line (Works in Eclipse but not from Command Line)
By rosco544 in forum NetworkingReplies: 16Last Post: 09172011, 02:41 AM 
[jFreeChart] Converting screenpoints to points, which are relative to the axis
By fyaxic in forum AWT / SwingReplies: 1Last Post: 08112011, 10:46 AM 
How to move the points on a predrawn line?
By pizzadude223 in forum Java AppletsReplies: 1Last Post: 07202010, 12:56 PM 
Formatting java command line output  Multi line string
By dricco in forum New To JavaReplies: 2Last Post: 07022010, 02:20 PM 
given number of points(cordinates) , find max points lie on the same line ?
By Hayzam in forum New To JavaReplies: 2Last Post: 08242008, 12:30 AM
Bookmarks