Enjoy the fun of physics with simulations!

Backup site http://enjoy.phy.ntnu.edu.tw/ntnujava/

Title: Line PatternsPost by: Paralias on December 11, 2007, 03:36:48 pm
Hallo everybody! ;D
Newbie here ;D I have an exercise from my University and i don't know how to do it. Here it is... I want my applet to read from the file coord_data_file.txt an Integer for example N=5 (the number of points) and the five points,for example 16384 19200 16384 18666 16384 32000 16384 21761 10000 10000 The points must be between 0 and 32768 To read the points we must use the nextInt() method of java.util.Scanner And what the program should do is the following... We must draw the points calling the PointPlotter.java(i will give you a .zip with all the files included) After that we choose a point (we name it p).We compare the angle that it makes with each one of the other points (we name it q) with the compareTo method. Then,we sort the points according to the angle that they make with the p. We check if 3 or more of the sorted points have the same angle to p.If we find them then all these points belog to the same straight line. So,please,can anyone help me ??? ??? You can download all the files from here:http://eclass.aueb.gr/TMA212/document/%C5%F1%E3%E1%F3%DF%E5%F2/%C5%F1%E3%E1%F3%DF%E1%202/assignment2.zip And some images here:(http://img227.imageshack.us/img227/1653/assignment2ik6.th.jpg) (http://img227.imageshack.us/my.php?image=assignment2ik6.jpg)(http://img507.imageshack.us/img507/1404/assignment2ga3.th.jpg) (http://img507.imageshack.us/my.php?image=assignment2ga3.jpg) Title: Re: Line PatternsPost by: Fu-Kwun Hwang on December 11, 2007, 09:43:27 pm
I believe it is your homework. You can not just say you do not know how to do it.
You need to indicate where you need help. Can you read data from the file? Do you know how to use nextInt() method. If you do not know, try to find information. Do you know how to draw the points by calling the PointPlotter.java provided by your teacher. ... I will try to help. But I can not do it for you. If I do it for it. Then it is not really good for you, and it is not fair,either. You need to learn the skill to be able to find a job later on in real world. ;) Title: Re: Line PatternsPost by: Paralias on December 12, 2007, 06:36:52 pm
Thanks for answering.
The point with my homework is that the teacher has never told us anything about these methods, or gave us an example, so i don't know how to do it. Anyway,i'm not asking you to do it for but help me with it. I'll try to open the txt file and read from it,but i don't know how to use the nextInt() method, or draw the points. Can you give some skills so i can try doing it? Title: Re: Line PatternsPost by: Fu-Kwun Hwang on December 12, 2007, 09:49:14 pm
Your teacher did not tell me about those methods,either.
But your teacher told you that use the nextInt() method of java.util.Scanner So I go to google ,type java.util.Scanner, and I found many pages. For example: Scanning Text With java.util.Scanner and Covariant Return Types (http://java.sun.com/developer/JDCTechTips/2004/tt1201.html)... How to draw the point: your teacher already provided you files. You need to read those files and find out how to do it. If you still have problem after you have read it, you can post your question with what you have read. But you need to read it first. Title: Re: Line PatternsPost by: Paralias on January 03, 2008, 07:20:16 pm
Hallo again and HAPPY NEW YEAR!! ;D ;D
I made some things with this project and you can see it in the attached file. I've drawed the Ox , Oy lines,i've opened the file and have read all the point and also i've drawned them. For each point p,i have made my program to find the points that are in the same line with p if they have the same x or the same y.Now,according to the description of my exercise i have to: for each point p i have to make my program to find the angle that each other point q makes up with the p and sort all points according to the angle that they make up.This must be done using the HeapSort in base with the MaxPQ.java We must name this class PointHeapSort.java This algorithm must use the compareTo method for objects with type of Point. So,i must make a class Slope for couples <angle, Point> which is going to make the Comparable and the method compareTo will sort two couples according to th angle that they have. The class PointHeapSort will contain only one method: void sort(List<Slope> l) Can you please help me?I am desperate and i don't know what to do next. Title: Re: Line PatternsPost by: Fu-Kwun Hwang on January 04, 2008, 09:39:14 am
To find the angle between points you can use vector to calculate it.
First transfer angle between 3 points to angle between to vectors. Assume you have 3 points: A(xa,ya), B(xb,yb), C(xc,yc) And if you want to find angle between AB and AC 1. create two vector AB=(xb-xa,yb-ya), AC(xc-xa,yc-ya) 2. inner product between two vectors AB AC =|AB|*|AC|*cos(cta) You can cllculate cos(cta)= inner product of two vector/ (|AB|*|AC|) to find angle cta where |AB| is the length of vector AB. I think you know how to do the sorting. Title: Re: Line PatternsPost by: Paralias on January 04, 2008, 04:38:35 pm
I thought of calculating the angles with the Math.atan2 function.
For example: if i have the points A(xa,ya), B(xb,yb), C(xc,yc) and i want to find angle between AB and AC i will do for the AB: angle=(yb-ya , xb-xa) and for the AC: angle=(yc-ya , xc-xa) And i will save each angle in a vector,so i can sort them later. Is it wrong? Title: Re: Line PatternsPost by: Fu-Kwun Hwang on January 04, 2008, 08:11:45 pm
It is sound good to me.
Title: Re: Line PatternsPost by: Paralias on January 07, 2008, 01:50:47 pm
Ok,now what is wrong with this code?
Why the compareTo is wrong?It returns 0 even for different angles. Can you please help me?Today i have to submit it. Can you fix me the problem? The whole code is in tha attched file. Title: Re: Line PatternsPost by: Paralias on January 07, 2008, 01:57:15 pm
I forgot to say that the programm should print: (16384, 32000) -> (16384, 18666)
for the input: 16384 19200 16384 18666 16384 32000 16384 21761 10000 10000 Pleasa Help me Title: Re: Line PatternsPost by: Fu-Kwun Hwang on January 07, 2008, 09:10:51 pm
I did download your zip file. However, there are 9 java files in the zip file.
I do not have time to read all those files (more then 40K of java code). If you can write down the essential code. May be I can try to help you. But, I really do not have time to read all your java code. There is no way I can do this kind of things for everyone. Sorry! |