473,396 Members | 2,011 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,396 software developers and data experts.

Drawing spiral in java.........

38
Hello ,

Im doing a java project in java 1.5 version and i need to draw the spiral . The problem is the user has to draw a box or rectangle of any size on an image and the central point of that box should be taken and a spiral should be drawn automatically starting from central point and also the box which they have drawn should be able to move and place it somewhere else in the picture. how to achieve this.

Kindly help me.
Thanks in anticipation.
Oct 25 '07 #1
4 6244
JosAH
11,448 Expert 8TB
Hello ,

Im doing a java project in java 1.5 version and i need to draw the spiral . The problem is the user has to draw a box or rectangle of any size on an image and the central point of that box should be taken and a spiral should be drawn automatically starting from central point and also the box which they have drawn should be able to move and place it somewhere else in the picture. how to achieve this.

Kindly help me.
Thanks in anticipation.
The "should be able to move and place it somewhere else in the picture" is the
most complicated part of it all and you have to exactly define what user mouse
gesture does what:

1) The user clicks the mouse and keeps it clicked and moves the mouse; this
should (or could define a rectangular area).

2) when the user releases the mouse button the other corner of the rectangle is
defined and the spiral can be drawn.

3) The user clicks the mouse and keeps it clicked and moves the mouse. Now
what should be done? The compound gesture is identical to 1). Should a second
spiral be drawn or should the first spiral be moved if the mouse was clicked in
the bounds of the rectangle defined by prior steps 1) and 2)?

What should happen if the user repeats steps 1) and 2) *outside* the bounds of
the first rectangle?

Think this over before you start coding. The actual drawing of a spiral is the easy
part.

kind regards,

Jos
Oct 25 '07 #2
sumuka
38
The "should be able to move and place it somewhere else in the picture" is the
most complicated part of it all and you have to exactly define what user mouse
gesture does what:

1) The user clicks the mouse and keeps it clicked and moves the mouse; this
should (or could define a rectangular area).

2) when the user releases the mouse button the other corner of the rectangle is
defined and the spiral can be drawn.

3) The user clicks the mouse and keeps it clicked and moves the mouse. Now
what should be done? The compound gesture is identical to 1). Should a second
spiral be drawn or should the first spiral be moved if the mouse was clicked in
the bounds of the rectangle defined by prior steps 1) and 2)?

What should happen if the user repeats steps 1) and 2) *outside* the bounds of
the first rectangle?

Think this over before you start coding. The actual drawing of a spiral is the easy
part.

kind regards,

Jos


Thank you Jos for showing interest in my question.
Now As you said when the user clicks and drags on the image a rectangle with a dotted lines has to be drawn once the user releases the mouse a spiral has to be drawn automatically within the rectangle and the dotted lines should disappear and when the user clicks on rectangle and moves it to the desired location the only the spiral has to be moved without any change to the background image.
Help me out with this.

Thanks in anticipation,
Oct 29 '07 #3
Ganon11
3,652 Expert 2GB
Well, since I'm not sure how you'll take care of moving the Rectangle (as I'm not too good with Java graphics), I'll try and help with actually drawing the spiral.

You can draw this spiral by using polar coordinates. A common equation for a spiral is r = (constant)<theta>. You can modify the size of the spiral by changing the (constant) value to be larger or smaller, to match your preference. Then you need to know the (X, Y) point to represent this (r, <theta>) point in the polar coordinate system. Using the conversions x = r * cos(<theta>), y = r * sin(<theta>), and r = (constant) * <theta>, you can find the x and y point of any point in your spiral.

So now you have an X, Y position, relative to the origin. The origin should be the center of your rectangle, so you will have to use it's position, width, and height to calculate the center point, then translate your X, Y point the appropriate amount.

All this is to plot 1 point on your spiral. Now you just need to compute many values of <theta> to get a smooth spiral.
Oct 29 '07 #4
sumuka
38
Well, since I'm not sure how you'll take care of moving the Rectangle (as I'm not too good with Java graphics), I'll try and help with actually drawing the spiral.

You can draw this spiral by using polar coordinates. A common equation for a spiral is r = (constant)<theta>. You can modify the size of the spiral by changing the (constant) value to be larger or smaller, to match your preference. Then you need to know the (X, Y) point to represent this (r, <theta>) point in the polar coordinate system. Using the conversions x = r * cos(<theta>), y = r * sin(<theta>), and r = (constant) * <theta>, you can find the x and y point of any point in your spiral.

So now you have an X, Y position, relative to the origin. The origin should be the center of your rectangle, so you will have to use it's position, width, and height to calculate the center point, then translate your X, Y point the appropriate amount.

All this is to plot 1 point on your spiral. Now you just need to compute many values of <theta> to get a smooth spiral.


Thanks for replying
I will try this out and get back to you if i need any help. :)
Oct 30 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: Remon Huijts | last post by:
Hi there, For a very specific service, I have created a PHP script that uses the GD library functions to create a PNG image from a few lines of XML data describing a simple diagram/drawing. It's...
2
by: Usman | last post by:
Hello Everyone. Can some one help me on this question , I studied a lot but still am unable to do this I need to print the following pattern using recursion in C++ , the end term is ' n '...
0
by: Tomi Holger Engdahl | last post by:
I am looking for a solution to add on-line drawing tool to a phpBB discussion board. The idea would be that the users can draw their own simple drawings with the tool and attach them easily as...
2
by: MBeckford05 | last post by:
Hello There ! I would like help, in writing a Java program to output an Archimedean Spiral to the screen. I have read on the net what a Archiemedian Spiral is. But I'm not too familiar with...
3
by: MBeckford05 | last post by:
Hi Everyone, I am placed with a problem. How to write a program in Java to produce the Archimeadean Spiral. The progam should look like an Archimedean spiral on the screen. Any help in hoe to...
8
by: mail2sandeepnl | last post by:
Hi how to spirally access 2 d array, ex: for input array 1 2 3 4 5 6 7 8 9 10 11 12 output should be like : 1,2,3,4,8,12,11,10,9,5,6,7
1
by: sumuka | last post by:
Hello, Can Anybody tell me how to draw a simple spiral in java ? Thanks in anticipation,
1
by: sumuka | last post by:
Hello, I'm doing a java project in which I have a rectangle which is drawn by the user by dragging the mouse and hence the size of the rectangle can vary for each execution. Now i need to draw a...
1
by: sheephead86 | last post by:
Hi, I'm pretty new to java, and I have a small problem involving drawing a rectangle on a java applet.Firstly this is not a plea for someone to help me with this peice of work, I just need pointing...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.