NTNUJAVA Virtual Physics Laboratory
Enjoy the fun of physics with simulations!
August 29, 2014, 11:16:21 pm *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
The softest thing overcomes the hardest thing in the universe. ...Lao Tzu (570-490 BC)
Google Bookmarks Yahoo My Web MSN Live Netscape Del.icio.us FURL Stumble Upon Delirious Ask FaceBook

Pages: [1]   Go Down
  Print  
Author Topic: Line Patterns  (Read 9778 times)
0 Members and 1 Guest are viewing this topic. Click to toggle author information(expand message area).
Paralias
Newbie
*
Offline Offline

Posts: 6



«
Embed this message
on: December 11, 2007, 03:36:48 pm »

Hallo everybody! Grin

Newbie here Grin

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 Huh Huh

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:
Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3054



WWW
«
Embed this message
Reply #1 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.  Wink
 
Logged
Paralias
Newbie
*
Offline Offline

Posts: 6



«
Embed this message
Reply #2 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?
Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3054



WWW
«
Embed this message
Reply #3 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 ...

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.
Logged
Paralias
Newbie
*
Offline Offline

Posts: 6



«
Embed this message
Reply #4 on: January 03, 2008, 07:20:16 pm »

Hallo again and HAPPY NEW YEAR!! Grin Grin

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.


*** There are 1 more attached files. You need to login to acces it!
Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3054



WWW
«
Embed this message
Reply #5 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.
Logged
Paralias
Newbie
*
Offline Offline

Posts: 6



«
Embed this message
Reply #6 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?
Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3054



WWW
«
Embed this message
Reply #7 on: January 04, 2008, 08:11:45 pm »

It is sound good to me.
Logged
Paralias
Newbie
*
Offline Offline

Posts: 6



«
Embed this message
Reply #8 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.


*** There are 1 more attached files. You need to login to acces it!
Logged
Paralias
Newbie
*
Offline Offline

Posts: 6



«
Embed this message
Reply #9 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
Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3054



WWW
«
Embed this message
Reply #10 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!
Logged
Pages: [1]   Go Up
  Print  
The softest thing overcomes the hardest thing in the universe. ...Lao Tzu (570-490 BC)
 
Jump to:  


Related Topics
Subject Started by Replies Views Last post
collision between twp particles in one dimension(along a line)
Examples for beginner who want to learn EJS
Fu-Kwun Hwang 0 9171 Last post October 10, 2007, 03:13:55 pm
by Fu-Kwun Hwang
Straight-line mechanisms
Molecular Workbench
concord 0 5502 Last post November 18, 2007, 12:01:21 am
by concord
Ball line collision and response. multiple collisions at once
Request for physics Simulations
slayer 64 4 9612 Last post November 10, 2010, 08:55:50 pm
by lookang
Why we need High Voltage Transmission Line
electromagnetism
ahmedelshfie 0 2905 Last post July 14, 2010, 02:43:32 am
by ahmedelshfie
Transmission line
Ejs simulations from other web sites
ahmedelshfie 0 2828 Last post September 22, 2010, 06:56:28 pm
by ahmedelshfie
Powered by MySQL Powered by PHP Powered by SMF 1.1.13 | SMF © 2006-2011, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 0.067 seconds with 22 queries.since 2011/06/15