I’m trying to create a sunflower effect on canvas, with an arc, and my geometry skills are rusty.
To start, I created an origin point somewhere in the middle of the canvas, Origin (X1, Y1)
Then I create get the Mouse Position Mp (Xm, Ym)
Now if I make an imaginary line from Origin to Mp, then Mp should be the point that bisects the arc with a new smaller origin point which is in the direction of the Origin, that will define the arc with a static radius (say 20). All three points Origin, Mp and the smaller Radius should form a straight line.
I want it to cut through the centre of the arc with a static radius (say 20) regardless of how close of far the mouse is from Origin.
So, if you imagine a clock. If the middle part where the hands connect is Origin.
- If the mouse is at the 3 o’clock position the Arc looks like a “)”
- If the mouse is at the 9 o’clock position the Arc looks like a “(”
- If the mouse is at the 12 o’clock position the Arc looks like a “(” if it were rotated 90°
- If the mouse is at the 6 o’clock position the Arc looks like a “(” if it were rotated 270°
- etc…
And the mouse is on top of that Arc.
For my question, specifically it’s not so much the how to get points, or mouseevents or anything, but assuming I have {X1,Y1} and {Xm,Ym}, what is the math needed to make an arc as described above?
Or for the JS/jQuery experts, the arc() params?
Edit: a very poor photoshop render
The bottom right one has a mouse added to show generally where the mouse pointer is at the time the arc/curve is drawn.
2
Answers
Adding Just because:
The simplest way is to adjust the starting & ending angles of the arc command.
You can draw a series of arc’s to form your flower.
Hint: If you want your petals to be less round and more curved, you might use
quadraticCurveTo
instead of arcs to draw the outside of the petals.Good luck with your project!
[ Addition based on more information ]
Yep, I think you’ve got it!
Start with the mouse position
mcx,mcy
.Define an angle that a smaller circle centerpoint is versus the mouse position
radianAngle
.Define how far that small centerpoint is away from the mouse centerpoint
radius
.Calculate the centerpoint of the small circle:
Define the radius of the smaller circle
smallRadius
.Define the total sweepAngle you want on the smaller arc
sweepAngle
.Define the starting & ending angles of the arc on your small circle. This is actually easy because you want the small arc to “point” at the mouse point. Hint: The center of the small arc must always be the at the midpoint of the
radianAngle
. Therefore, thestartingAngle
=( radianAngle - sweepAngle/2
.So finally your small angle that “points” to the mouse becomes:
Cheers!