473,395 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

geometry/java problem

Here's somewhat of an interesting problem. I am creating a class called
Rectangle. It takes in 4 sets of Cartesian coordinates (i.e. (x,y)
coordinates.). I'm assuming that the rectangle can be rotated too when
receiving these coordinates.
How would I go about setting methods to
A>"order" them (so that when i trace the outsides, point A,B,C,D all are
continous, as opposed to crossing in the "middle"...
B> testing that they are equal sides BUT(this has been where i get stuck)
all 90 degree angles...

Just so you know that i've been thinking abou this rather than throwing it
at you, here have been my approaches..
Assuming points A, B, C, D
First i figured
if ((side AB==side DC) &&(side BC==side AD))
then it is a quadrilateral with 2 pairs of equal sides.. But a parallelogram
also fits this bill.
I figure this might get complicated. There were numerous things i thought
of. I guess my goal is to KISS, but I have a feeling it won't be that
simple... Any ideas?
This isnt for school.. just for my own.... ?entertainment?... heheheh

Thanks,
Dave
Jul 17 '05 #1
3 2527
David E. wrote:
Here's somewhat of an interesting problem. I am creating a class called
Rectangle. It takes in 4 sets of Cartesian coordinates (i.e. (x,y)
coordinates.). I'm assuming that the rectangle can be rotated too when
receiving these coordinates.

How would I go about setting methods to
A>"order" them (so that when i trace the outsides, point A,B,C,D all are
continous, as opposed to crossing in the "middle"...
Probably the easiest way to handle this is to ensure that the values
can only be input in order. If you're storing them in an array called
"verticies", for example, just ensure that the points are in a circuit
when you move from point[k] to point[k+1].

If you need this for some sort of constructor that takes four sets of
co-ordinates to ensure the user entered them in the proper order, the
best thing to do is to calculate the points of intersection for each
pair of possible edges. There are only 6 possibile edges, two of which
will intersect for any quadrilateral. Discard these two. Having
discarded these two, you now know what edges don't exist, and can use
the remaining four to determine an ordering.

(What you're really doing here is figuring out a Hamilton Circuit for
the figure. Being a four-sided figure, there will only be 8 possible
circuits, all of which form a quadrilateral (with four different start
points travelling in each of two directions).
B> testing that they are equal sides BUT(this has been where i get stuck)
all 90 degree angles...
Try using the Pythagorean theorem in reverse. Take any three points
representing two adjacent edges of your quadrilateral. Calculate the
length of the sides this triangle would form. Using the central vertex
(the one at the corner you want to test for right-angledness), calculate
to see if the sum of the squares of its two edges is equal to the square
of the opposite side. If it is, you have a 90 degree angle. If it
isn't, you have some other angle (which, as I assume you're just testing
to see if the figure is a rectangle, should be all you care about).

Note that you'll probably want some delta in your comparison, as
rotated rectangles will probably see some rounding errors in your length
calculations. So when you calculate the squares (and the sums of the
squares), being off by a very tiny bit should be acceptable. This will
mean that some non-rectangles may wind up being considered "acceptable"
by your code, but this is probably better than having the code _reject_
proper rectangles just because of precision problems.
First i figured
if ((side AB==side DC) &&(side BC==side AD))


Be careful of your nomenclature here. What you want to check is not
that the two lines are equal (which would mean that they occupied the
exact same space) -- you want to test to see if their _lengths_ are equal.

HTH!

Brad BARCLAY

--
=-=-=-=-=-=-=-=-=
From the OS/2 WARP v4.5 Desktop of Brad BARCLAY.
The jSyncManager Project: http://www.jsyncmanager.org

Jul 17 '05 #2
"David E." <no*****@nothing.com> wrote in message news:<bG******************@nwrdny02.gnilink.net>.. .
Here's somewhat of an interesting problem. I am creating a class called
Rectangle. It takes in 4 sets of Cartesian coordinates (i.e. (x,y)
coordinates.). I'm assuming that the rectangle can be rotated too when
receiving these coordinates.
How would I go about setting methods to
A>"order" them (so that when i trace the outsides, point A,B,C,D all are
continous, as opposed to crossing in the "middle"...
B> testing that they are equal sides BUT(this has been where i get stuck)
all 90 degree angles...
For a simple initial test, if the two leftmost points have
the same x-coordinate, then the figure is either not a rectangle,
or is a rectangle oriented along the coordinate axes. Test for
rectangle-ness in this case is obvious.
If the two leftmost points don't have the same x-coordinate,
find the leftmost, topmost, rightmost, and bottommost points. If
this is a rotated rectangle, these points must all be different
(one point can't be both topmost and rightmost, etc.). Now
ordering the points as: leftmost, topmost, rightmost, and
bottommost will give you a clockwise order. To make sure it is
a rectangle, check that opposing sides are the same length, and
the diagonals are the same length (you can learn the diagonal
trick by watching "This Old House" reruns - no math class
needed).
Floating point coordinates are not exact, so you can not use
== to compare for sameness. Construct an "areSame" method that
computes the absolute value of the difference and returns true
if it is below some threshold. If scaling is arbitrary (the
rectangle can be very small or very large) then the threshold
must be a function of current scale - for example you could use
a fraction of the difference in x-coordinate of leftmost and
rightmost points. Otherwise, you can choose an appropriate
threshold based on the known range of possible rectangle sizes
and granularity of input.
-Larry Barowski

Just so you know that i've been thinking abou this rather than throwing it
at you, here have been my approaches..
Assuming points A, B, C, D
First i figured
if ((side AB==side DC) &&(side BC==side AD))
then it is a quadrilateral with 2 pairs of equal sides.. But a parallelogram
also fits this bill.
I figure this might get complicated. There were numerous things i thought
of. I guess my goal is to KISS, but I have a feeling it won't be that
simple... Any ideas?
This isnt for school.. just for my own.... ?entertainment?... heheheh

Thanks,
Dave

Jul 17 '05 #3
For ordering, you can use the fact that for the given ordered rectangle
ABCD, the line segment AC will have the greatest length.

So, given the points P1, P2, P3, P4, arbitrarilty pick P1 as point A,
then caluclate the norms |P1P2|, |P1P3| and |P1P4|, the one that yields
the greatest value will be point C, then assign the others as B and D.

Note that this will only work if ABCD is indeed a rectangle.
-Alex
"David E." <no*****@nothing.com> wrote in
news:bG******************@nwrdny02.gnilink.net:
Here's somewhat of an interesting problem. I am creating a class
called Rectangle. It takes in 4 sets of Cartesian coordinates (i.e.
(x,y) coordinates.). I'm assuming that the rectangle can be rotated
too when receiving these coordinates.
How would I go about setting methods to
A>"order" them (so that when i trace the outsides, point A,B,C,D all
are continous, as opposed to crossing in the "middle"...
B> testing that they are equal sides BUT(this has been where i get
stuck) all 90 degree angles...

Just so you know that i've been thinking abou this rather than
throwing it at you, here have been my approaches..
Assuming points A, B, C, D
First i figured
if ((side AB==side DC) &&(side BC==side AD))
then it is a quadrilateral with 2 pairs of equal sides.. But a
parallelogram also fits this bill.
I figure this might get complicated. There were numerous things i
thought of. I guess my goal is to KISS, but I have a feeling it won't
be that simple... Any ideas?
This isnt for school.. just for my own.... ?entertainment?... heheheh

Thanks,
Dave


Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Jon | last post by:
Hello all, I'm certain this question has been asked before; I was unsure what terms to search for within the newsgroup archive to find the proper answer I wanted. Hopefully someone can point me...
7
by: Maxim Shemanarev | last post by:
I'd like to announce my project called Anti-Grain Geometry. http://www.antigrain.com Anti-Grain Geometry (AGG) is an Open Source, free of charge graphic library, written in industrially standard...
3
by: Otavio Macedo | last post by:
Hi, I am working with MySQL 4.1 and I got a table with a point field. I need to do an "offset" in all the points, that is, adding some deltaX to the X coordinate and a deltaY to the Y...
7
by: Chris | last post by:
Hi, If a user resizes a Toplevel window, or I set a Toplevel's geometry using the geometry() method*, is there any way to have the geometry reset to that required for all the widgets? I think...
11
by: Christopher Ireland | last post by:
Hello! Using the definition for en ellipse (http://en.wikipedia.org/wiki/Ellipse) I can draw an arc of points. However, the end points of this arc do not coincide with the end points of an arc...
2
by: =?Utf-8?B?QXRoZW5hQw==?= | last post by:
Hi, I have tried to draw a big long curve line with more than 10 thousands data sample using Geometry in WPF, and put it into the Scrollviewer. But the performace for scrolling is so poor. Does...
12
by: gsal | last post by:
What would be the easiest way to go about offering 3D graphics for the purpose of rendering geometry? Suppose engineers (my co-workes) have to design some enclosure, nozzle, bracket, or whatever...
2
by: JasmynGomez | last post by:
This was an assignment for our JAVA class I am still a beginner and my code keeps getting errors, and I am so confused. I've tried every different way I can think of, can someone please take a...
3
by: =?ISO-8859-1?Q?Norbert_P=FCrringer?= | last post by:
Hello, do you know an URL for me where to find a sample for an abstract Geometry class, where classes like Point, Line, Area are inherited. This sample should explain OOP (what is inheritance,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.