Jump to content
Search Community

Circle radius increase decrease pointer behaves abnormally

Owais1723 test
Moderator Tag

Go to solution Solved by Rodrigo,

Recommended Posts

Hello Everyone I hope you are doing well. I have a problem relating to the circle radius increase decrease pointer. so it works like when you drag the pointer away from the circle's center point it increases its radius and decreases when dragging towards the center point. it works fine but the pointer moves away from the circle border when you drag your mouse away from the pointer on the x-axis. I have provided the code pen so you can check it out thankyou ❤️.

See the Pen yLRxPpm by Owais-Ahmad (@Owais-Ahmad) on CodePen

Link to comment
Share on other sites

  • Solution

Hi,

 

The problem is in the math you're doing for calculating the distance constant. In an ellipse you'll need both the values on the X and Y axis for that, but a triangle circumscribed in a circle it's always an Isosceles triangle, that means both sizes are equal an the angles are 45 degrees:

isosceles-right-triangle-1635233855.png

On top of that you are overcomplicating this quite a bit IMHO. This is far simpler, cleaner, seems to work the way you intend and you don't have to worry about the user dragging on the X axis:

let radius = gsap.getProperty(table, "r");
const changeCircleSize = Draggable.create(dot, {
  type: "y",
  onDragStart: function () {
    dragCircle[0].disable();
  },
  onDrag: function () {
    table.setAttribute("r", Math.abs(radius - this.y));
  },
  onDragEnd: function () {
    dragCircle[0].enable();
  }
});

Here is a fork of your demo:

See the Pen poxOpLN by GreenSock (@GreenSock) on CodePen

 

Hopefully this helps.

Happy Tweening!

  • Like 5
Link to comment
Share on other sites

On 5/16/2023 at 9:00 PM, Rodrigo said:

Hi,

 

The problem is in the math you're doing for calculating the distance constant. In an ellipse you'll need both the values on the X and Y axis for that, but a triangle circumscribed in a circle it's always an Isosceles triangle, that means both sizes are equal an the angles are 45 degrees:

isosceles-right-triangle-1635233855.png

On top of that you are overcomplicating this quite a bit IMHO. This is far simpler, cleaner, seems to work the way you intend and you don't have to worry about the user dragging on the X axis:

let radius = gsap.getProperty(table, "r");
const changeCircleSize = Draggable.create(dot, {
  type: "y",
  onDragStart: function () {
    dragCircle[0].disable();
  },
  onDrag: function () {
    table.setAttribute("r", Math.abs(radius - this.y));
  },
  onDragEnd: function () {
    dragCircle[0].enable();
  }
});

Here is a fork of your demo:

 

 

 

Hopefully this helps.

Happy Tweening!

Man that was smooth. I didn't think about it that way thank you so much.  And more favour hwo to prevent the radius decrease upto only 20 radius it shouldn't be able to decrease than 20.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...