Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: How can I Drag a Point (represented as a Circle) along the Perimeter of a Circle ?

  1. #1
    Member
    Join Date
    Apr 2024
    Posts
    39
    Thanks
    14
    Thanked 1 Time in 1 Post

    Default How can I Drag a Point (represented as a Circle) along the Perimeter of a Circle ?

    Hello everybody.

    I'm trying to solve the following programming exercise:



    (Drag points)

    Draw a circle with three random points on the circle.

    Connect the points to form a triangle.

    Display the angles in the triangle.

    Use the mouse to drag a point along the perimeter of the circle.

    As you drag it, the triangle and angles are
    redisplayed dynamically, as shown in Figure.

    For computing angles in a triangle, see Listing 4.1.


    In order to solve this exercise, I need to solve several "sub-exercise" challenges.

    I've already solved the majority of the issues stopping me to solve this problem.


    I already know how to draw a circle with three random points on the perimeter of that same circle.


    I already know how to connect three points to form a Triangle.

    I've created a Triangle class that allows for the creation of two types of Triangles.

    One Triangle only receives the length of the three sides.

    The second Triangle receives three Points(x, y) and it calculates the sides.


    I already know how to Display the angles in the triangle.

    The Triangle class has a method to get the angles of the three vertices of the Triangle.


    I already know how to Drag a Point Vertice (represented as a Circle) of a Triangle and
    after I stop draggging it, the triangle and angles are redisplayed dynamically.


    I just don´t know how to drag a Point (represented as a Circle) along the Perimeter of a Circle.

    Thank you,

    Rogério

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How can I Drag a Point (represented as a Circle) along the Perimeter of a Circle ?

    how to drag a Point (represented as a Circle) along the Perimeter of a Circle
    Where does the cursor need to be located to do the drag?
    Does the cursor need to be precisely on the circumference of the circle that is to be moved
    or just anywhere within it
    or where?

    I assume the center of the circle to be move needs to stay on the perimeter of the Circle.
    You have the x,y of the cursor and the x,y of the center of the circle.
    As the cursor moves there will be changes in its x,y location. Use those to change the center of the circle's location.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Apr 2024
    Posts
    39
    Thanks
    14
    Thanked 1 Time in 1 Post

    Default Re: How can I Drag a Point (represented as a Circle) along the Perimeter of a Circle ?

    Hello Norm.

    Thank you for your answer.

    I've kept the same approach for moving circles as the previous Thread I've posted in this Forum, in the Java FX Section.

    I've created a program to solve a previous programming exercise:



    (Geometry: display angles)

    Write a program that enables the
    user to drag the vertices of a triangle and
    displays the angles dynamically as the
    triangle shape changes,
    as shown in Figure.

    The formula to compute angles is given in Listing 4.1.

    This program allows the user to click inside any part of the Circle (that is also one vertice of the Triangle) to be dragged, and drag it anywhere.

    When the user releases the Button (stops dragging the circle), the Triangle lines are updated and the Triangle Angles are also updated dinamycally.

    My problem is not with the drag of the circle, but as to make the dragging "precise".

    I need the dragging "precise" so that if I have a Circle with Center (x, y) inside the perimeter of another Circle (Big Circle) before drag, I can only drag that Circle to another position inside the perimeter of the Circle (Big Circle).

    Right now I have a sort of "Free Drag", that is, I can Drag one Circle to any position inside the Scene.

    Thank you,

    Rogério

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How can I Drag a Point (represented as a Circle) along the Perimeter of a Circle ?

    make the dragging "precise".
    What do you have now? Why isn't it precise?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Member
    Join Date
    Apr 2024
    Posts
    39
    Thanks
    14
    Thanked 1 Time in 1 Post

    Default Re: How can I Drag a Point (represented as a Circle) along the Perimeter of a Circle ?

    Hello Norm.

    I'm having a problem with the Math necessary to solve this exercise.

    I can create the initial "Random" points in the perimeter of the Circle (Big Circle).

    I have to use random angles and I can easily place three (or even more) points in the Perimeter of the Big Circle.

    I know I'm repeating myself but the problem is to drag the point (circle) and make it appear that is being dragged along the Perimeter of the Big Circle.

    I wish you all a good weekend.

    Thank you

    Rogério

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How can I Drag a Point (represented as a Circle) along the Perimeter of a Circle ?

    I'm having a problem with the Math
    Yes, it is more of a math problem than a java programming problem. Once you have the design or algorithm then it will be a java programming problem which I can help with. I am not a mathematician.
    The only math I can think of is Pythagorean theorem. Given the radius is the hypotenuse and either x or y, the value of the other y or x can be computed.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Member
    Join Date
    Apr 2024
    Posts
    39
    Thanks
    14
    Thanked 1 Time in 1 Post

    Default Re: How can I Drag a Point (represented as a Circle) along the Perimeter of a Circle ?

    Hello Norm,

    Thank you,

    Rogério

Similar Threads

  1. Replies: 7
    Last Post: October 8th, 2024, 10:08 AM
  2. Displaying a Circle on an IMage
    By Saadat in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 7th, 2018, 05:53 PM
  3. Replies: 1
    Last Post: January 3rd, 2012, 06:28 PM
  4. java (circle)
    By coder.freak in forum Member Introductions
    Replies: 3
    Last Post: March 26th, 2011, 12:01 PM
  5. Implement dragging a circle
    By jolly in forum AWT / Java Swing
    Replies: 0
    Last Post: August 19th, 2009, 02:48 PM