### Archive

Archive for August, 2009

## Quadratic Hermite Curves Part 3

In part 2 of this series, we looked at the geometric interpretation of the end tangent of the quadratic Hermite curve.  There was an issue in terms of relating the vector endpoints in the parent coordinate system to the tangent vector that is computed based on delta-x and delta-y from the point P0.  Compensating for this issue was necessary in order to draw the tangent vector.

I also suggested computing a unit vector in the direction of the tangent as an exercise so that it could be drawn at constant length.  The two questions addressed in this post are

1) Do we constantly have to adjust for the deltas between T and P0 in order to draw a tangent to the curve at any parameter value in [0,1]?

2) How exactly do we compute a unit vector in the tangent direction and draw a constant-length tangent segments?

The answer to question 1 is no.  The compensation, if you want to call it that, is already accounted for in the polynomial coefficients which are computed based on the delta-x and delta-y between T and P0.  So, we can use P’(t) = b + 2ct (review the computation of the ‘b’ coefficient in the code).  In part 2, we substituted for b and c in terms of the endpoints of the original vectors.  Once the polynomial coefficients are computed, we can use them directly for the derivative at any parameter value.

This raises the question of why part 2 in the first place?  The geometric formula for the end tangent in terms of the original points (and T) will be important in part 4 when we discuss joining quadratic  Hermite segments.

For question 2, the unit tangent vector is P(t)/||P(t)||, where ||.|| is the vector 2-norm.  Let dx = x’(t), dy = y’(t), and ux = x-component of unit tangent vector, uy = y-component of unit tangent vector.

Then, we can write

ux = dx/sqrt(dx*dx + dy*dy)

uy = dy/sqrt(dx*dx + dy*dy)

Since this is a unit vector, multiply by any amount to draw a constant-length vector of that amount.  For example, to draw a tangent segment of 40px length,

moveTo( x(t), y(t) ), then lineTo( x(t)+40*ux, y(t) + 40*uy )

This concept is illustrated in a simple demo, a screenshot of which is shown below.

Tangent to a quadratic Hermite curve

The slider adjusts the parameter value for the tangent segment between 0 and 1. (As an aside, these demos require the F10 player).

In the next post in this series, we will see how to join two quad. Hermite curves with continuity at the join.  In the mean time, think about what is the maximum continuity that could possibly be enforced at a join point?  Hint:  What degree is the derivative of a quadratic polynomial?

Categories: Flash, Math

## Elliptical Arcs for Aribtrarily Rotated Ellipse

I’ve received a few requests over the last several weeks for methods to approximate elliptical arcs with quad. Beziers for an ellipse that is rotated at an arbitrary angle.  Further, the requests were for straight actionscript; no Flex and no Degrafa.  Oh well, not as fun, but your wish is my command

I originally worked with this algorithm for a cubic Bezier approximation in a computational geometry class in 1981.  I don’t have an original attribution for the algorithm, but suspect it goes back to the 1970′s.  Fortunately, the quad. case is easier, although strict error analysis is still tricky.  For ellipses with major/minor axes of a few hundred px, it seems that approximating the arc in segments spanning no more than PI/8 is an acceptable starting heuristic.  You may need something more sophisticated for much larger cases.

A screenshot of the demo (Flash CS3) is shown below.  The code is straight AS on the timeline; no frills, no classes, just a straightforward implementation of the algorithm.

Approximating an arc of a rotated ellipse

The code draws a simple wedge.  You can download it here.  If there is sufficient interest, I might incorporate this into Degrafa (whose elliptical arc class does not take rotation into account if memory serves).

Enjoy!

Categories: Flash, Math Tags: , , , ,

## Babolat Revenge Review Part 1

This is the first in a two-part review of the new Revenge string from Babolat.  I currently play a VS Team 16/Pro Hurricane Tour 17 hybrid, so I’m reviewing Revenge both fullbed and in a hybrid.  I normally string in the 50-53 range, so I first tried Revenge 17  in a fullbed @ 54lb.

I had previously tested Pro Hurricane Tour and xCel Power as a fullbed in the same racquet, both at an average tension of 53.  The xCel Power felt great but had a tendency to spray balls.  It was better crossed with xCel Premium.  The Pro Hurricane tour was so responsive in my head-light racquet that it had some low-frequency vibration that was very noticeable on touch shots and light volleys.  Crossed with the VS Team gut, however, performance is terrific in a hybrid.

My first impression of Revenge was that it was a cool-looking (red) string with a unique popping sound at impact.  At lower tension, the string provided expected power on groundstrokes but with unexpected control.  This is one string you can take a hard swing at the ball and if you miss, it’s all on you.  While not advertised as a comfort string, I did not notice any arm soreness after hammering on the string with 4.0/4.5 players for about an hour.

Volleys were very crisp and it almost seemed like the string performed better at the net than on the baseline.  If you have a relatively flat first serve, you will probably upgrade your first serve with Revenge.  Spin was definitely weaker than Pro Hurricane Tour (as would be expected) and from what I remember hitting with xCel Power.  You might lose a bit on a sliced second or heavy topspin first serves.

Coming from a gut player, my next observation is almost predictable.  Revenge does not have the feel I like on touch shots.  If these are an important part of your game, then you will not like this string in a fullbed.

After about 3 1/2 hours of hitting under various circumstances (including in the middle of the day in Texas heat), there was very little string movement.  The person who strung my racquet indicated no issues in the stringing and little coil memory.  DIY’ers will probably find it an easy job to string.

Overall, this string impresses me as good choice for 3.0/3.5 players looking for a power string without sacrificing control.  Revenge is advertised as a highly durable string with minimal tension loss.  That means you can afford to string at lower tensions without fear of the string becoming mushy after just a couple weeks of hard play (which happened to me with xCel Power).  I will continue to hit with the string and once I get to about ten hours, I’ll measure the tension and report back.

I believe 4.0+ players might consider Revenge as an alternative to say Big Banger, but only from the standpoint of adding control or getting a more arm-friendly string.  If you currently play a hybrid (especially a gut/poly hybrid), you would only want to consider Revenge as a substitute for your mains.  When my current hybrid is ready for restringing, I’ll see how Revenge compares as a main string to the Pro Hurricane Tour and then post part 2 of this review.

Categories: Tennis Tags: , ,

## Tennis Tip: Catch the Ball for Better Volleys

I don’t have an original attribution, but someone once said that a good volley motion is similar to catching a baseball.  A fielder does not swing their arms towards the ball.  The arm is extended outward to place the glove in a position to intercept the ball.  Instead of a baseball glove, perhaps a Lacrosse stick is a better visualization.  Think of the racquet face as something you might use to simply catch the ball.  There is no need for a swinging motion as the ball’s momentum will supply sufficient power.

For isntances where you want to supply more power to volley a softer shot, use shoulder rotation to move the racquet towards the ball, keeping it positioned in front of you.

You can practice this technique by having someone feed you short balls and catch them with your hand.  Think about duplicating this motion with an actual volley and it may help you overcome that swinging instinct that leads to inconsistency.

Good luck with the game!

Categories: Tennis

## Quad Hermite Curves Part 2

In the previous post, we saw how to construct a quadratic curve from two points and a start tangent.  If the eventual goal is to join one or more of these segments, we need to know how to compute the end tangent.  Note from the prior post that the curve’s derivative is P’(t) = b + 2ct, with b = T and c = P1 – P0 – T.  From this, we have P’(t) = T + 2(P1 – P0 – T)t .  The end tangent occurs at t = 1, so P’(1) = 2(P1-P0) – T.  The geometric interpretation of this formula is illustrated in the following diagram.

End Tangent of Quadratic Hermite Curve

The constituent elements of the formula are illustrated with dashed lines (courtesy of a Degrafa decorator).  At first glance, it seems that the vector 2(P1-P0) – T is not at all tangent to the curve at P1.  Recall that with Hermite curves, the tangents are typically described relative to a parent coordinate system.  In the computations, the tangent is computed relative to the first interpolation point.  The endpoint of 2(P1-P0) – T is used to create delta-x and delta-y values from P0.  These deltas are added to P1 to draw the actual tangent vector, illustrated in red.

In the online demo, you may move either P0, P1, or T and see each element of the construction (without labels).  The length of the tangent segment varies based on the deltas.  As an exercise, try computing a unit vector in the direction of the tangent and draw it with constant length.

There is an issue with the dash line decorator in terms of altering the dash width and spacing.  I did not write the decorator, so I’m not familiar with the internals.  If time allows, I will look into it.  In the mean time, study the code and in the next post of this series, we’ll look at the general tangent to the curve in more detail.  After that, we will see how to join two quadratic Hermite segments with continuity at the join.

View demo

View source

Categories: Degrafa, Flex, Math Tags: , , ,

## Quad Hermite Curves Part 1

A quadratic Hermite curve is constructed with two points (P0 and P1) and a tangent vector, T, as shown in the following diagram.

Construction of a quadratic Hermite curve

The tangent vector may be either a start (out-tangent) or end (in-tangent) vector, although it is customary to make it a start-tangent.  This type of curve is rarely used in curve construction as quad. Beziers  are often preferred when one is designing with a quadratic curve.  One advantage to this type of curve segment (that we will exploit in the future) is the simplicity of its construction.

The quadratic curve is of the form P(t) = a + bt + ct2 . The derivative is of the form, P’(t) = b + 2ct. Three equations are needed to compute the coefficients, a, b, and c. There are given by P(0) = P0, P(1) = P1, and P’(0) = T. The solution to the 3×3 system of equations is

a = P0

b = T

c = P1 – P0 – T

When computing the coefficients, the tangent vector is constructed using P0 as an origin.  Given the endpoint in the parent coordinate system, the delta between T and P0 is used in the computations.  This is illustrated in the accompanying demo.

In subsequent posts, we will look at the end tangent and how these quadratic segments can be joined (with continuity).

Categories: Flex, Math Tags: , ,

## Tennis Tip: Maintain Posture Through Impact

I think it was David Leadbetter who popularized the saying in golf of letting the dog wag the tail, not have the tail wag the dog.  The idea behind the saying was to let the larger muscles in the body control the movement of the smaller muscles, not react to their motion.  In other words, the hands and arms do not start the backswing in golf; they react in unison to movment in the larger back muschles.  The so-called ‘one-piece’ takeaway was thus popularized.

The tennis swing bears some similarity.  So many swings I study are dominated by arm motion.  The hips, back, and legs seem to come along for the ride.   This is very evident in the motion at and through impact.  I see people trying to put ‘body english’ on the ball to complete the stroke.

The two most common moves are standing up at impact and throwing the body around (particularly on the forehand side) just before impact.  The former move often comes from a psychological desire to add more height to the ball.  The latter move is often an attempt to direct the ball crosscourt or add more power.  In golf, we would call this coming ‘over the top.’  The downswing is started by ‘throwing’ the arms from the top, then the body tries to compenste by pulling around and to the left, which only throws the clubhead even further outside the swing path, causing an outside-to-in motion.  With an open clubface, this produces a slice; a pull results from a closed clubface.

In either case, we should not be using the upper body to ‘add’ to arm motion at impact.  The upper body should be positioned prior to impact.  Its role in the swing is one of stabilization and being part of the total kinematic chain.  If the body is rapidly rotated back around during impact, the racquet face is either closed or starting to close, so the result is a flatter swing path that has a tendecy to direct the ball downward.  With perfect timing, the ball can be hit low and hard, but net balls are a common result.  The compensation is additional body motion by raising and over-rotating at impact.  This causes the ball to often miss wide crosscourt or long.

Stroke inconsistency can often be traced to short-circuiting the kinematic chain, moving the arms too much and trying to compensate with body motion at impact.  With sufficient time to setup and hit a ball in the strike zone, the body should appear to rotate around the spine at impact with a relatively still head.  We see this so well in Federer’s strokes.  The body posture is formed prior to impact and remains relatively constant through impact as the kinematic chain is unwound.

Getting rid of body compensations takes some effort and I suggest you work with a professional instructor.  Identifying specific  compensations and setting up drills to alleviate the issue is important.  Two people that have apparently similar compensations may need completely different remedial action.  For example, I have a tendency to shift the body laterally back towards midcourt.  My instructor identified this as an attempt to recover too quickly and get into  position for the next shot.  So, we do lots of crosscourt drills where the goal of the drill is to maintain strict posture and consistently hit the ball back hard and deep (we usually try for 8-10 straight).

In golf, we used to say that you ought to be able to take a practice swing and see your left shoulder go under the chin on the backswing and see the right shoulder go under the chin after impact.  Take a practice swing with your racquet and look at your shoulders.  Do you really get the feel of pivoting around your spine?  Do the arms act in response to motion in the hips and shoulders or does the upper body react to motion in the arms?  Is the dog wagging the tail or the tail wagging the dog?

Good luck with the game!

Categories: Tennis Tags: ,

## Parametric Equation of a Line

I’m going to do one or two posts on quadratic Hermite curves and maybe extend that to splines.  One of the items in the upcoming demo is determining the vector that is twice the distance from another vector from P1 to P2.  This discussion came up elsewhere in the form of a question; given two points A and B, find the point C that is on the line from A to B at twice the distance from A to B.  I actually read the exchange after it was pretty much finished.  Lots of formulas involving distance, trig, and one based on the coordinate deltas to extend the line segment from B.

None of these are intrinsically wrong and it is always good to discuss a variety of solutions to a problem.  It is also useful to periodically back up and discuss fundamental concepts.  We are used to seeing the equation of a line in either two-point or slope-intercept form.  Given two points A and B, the parametric equation of the line is (1-t)A + tB .  This is a vector equation that yields two scalar equations, one for the x-coordinate and one for the y-coordinate and both int terms of t, i.e. x(t) and y(t).  There is another parametric form which is that of a line passing through a point and parallel to another vector, but that is another discussion for another time.  If you really want to impress people at the next Flash/Flex conference, you can say that the above equations represent a convex combination of the vectors A and B.  However, from that point onward, no one will want to talk with you

If the parameter, t is in [0,1], the resulting point is on the segment from A to B.  It is allowable for t to be outside this interval.  Values of t greater than one produce points on the line beyond B (in the direction of the vector AB).  Values of t less than zero produce points on the line beyond A in the opposite direction.

What about t = 2?  This produces the vector 2B-A.  Let dx = B.x – A.x and dy = B.y – A.y.  Let dx2 = (2B-A).x – A.x and dy2 = (2B-A).y – A.y.  Note that dx2 is 2B.x – 2A.x = 2(B.x – A.x) = 2dx.  The (Euclidean) distance from A to B is sqrt(dx*dx + dy*dy).  The distance from A to (2B-A) is sqrt(dx2*dx2 + dy2*dy2) = sqrt(4*dx*dx + 4*dy*dy) = sqrt(4(dx*dx + dy*dy)) = 2*sqrt(dx*dx + dy*dy) or twice the distance from A to B.  If you want to do even more math, you can extend this to arbitrary t-values.

There is no need to think about distances or angles.  It is possible to pre-compute the deltas and derive a formula that extends the line segment outward from B, but this involves unnecessary work and rethinking multiplier values to ‘contract’ the line segment in the other direction.  Everything you might need in this regard is already naturally present in the parametric line equation.

I know programmers can understand math, but prefer to deconstruct concepts from code, so there is a vey simple demo that goes along with this discussion.  A screenshot is shown below.

Parametric equation of a line

The demo starts with two points in a drawing area.  They can be dragged inside the white area, but you want to keep them relatively close to the middle of the area.  The slider represents the parameter (or t-value).  It starts at zero.  The red dot is the point on the line.  The slider ranges from -2 to 2, so you can see how values between 0 and 1 constrain the point to the line segment from A to B.  Notice the dot position when the slider is at its extreme values.

View demo

View source

It is good to periodically review basic and fundamental concepts.  I know many advanced readers will find this post boring, but if it helps at least a few people, then I think it’s worthwhile.  In the near future, we will look at how to construct a quadratic curve with two points and a tangent line.

Categories: Flex, Math

## Tennis Tip: Relax For Better Passing Shots

Everyone has a tendency to overhit (myself included), but it seems that even professionals feel a need to put some extra heat on a passing shot, which can lead to misses.  Passing shots can be difficult enough as they are most often hit on the run.  A substantial percentage of passing shots are down the line, meaning you must hit over the highest point of the net.  When margin for error is reduced, it is not good strategy to further reduce that margin by trying to hit the shot extra hard.

But, that’s not what our emotions dictate.  There is something about an opponent approaching the net that seems to require blowing the ball right past them at absolute maximum pace.  In reality, we have only one obligation and that is to win the point.  Blowing the ball past an opponent and well beyond the baseline or hitting it in the net only serves to reward the opponent for approaching in the first place.

We don’t receive any extra points for hitting the ball hard past someone.  There is an old saying that placement wins more points than power.  I’d like to add my own personal thought that a shot only needs to be as good as it needs to be, not better than it needs to be.   In other words, if I can safely slice a backhand down the line and pass someone, why try to make the shot better and hit a big topspin  backhand really hard while on the run?  Yes, it really looks impressive if I nail the shot, but what if I miss and fail to convert a break or give away the lead in a game?

All we need to do is win the point.   If you favor accuracy over power in your passing shots, then you will simply win more points.  Not only will your opponent back away from approaching the net, you can actually hit safe semi-drop shots and intentionally bring them into the net.  Use your passing shot as a winning strategy, not a defensive shot.

Now, there is one case where you might consider hitting a more powerful shot when someone approaches the net.  A lot of players are hitting approach shots down the middle of the court, even when the opponent is also near the middle.  The idea is that it is a safer shot and it forces the opponent to create an angle on the return shot which can be exploited on the following volley.

If someone approaches you in this manner, consider hitting the ball hard right back at them.  Do not create the angle they want from a middle approach.  Most 3.5 and lower players do not volley well when the ball is hit right at them.  It will be a defensive volley and open up the angle for you to position a passing shot or a lob.

When you go for the winning shot, discipline yourself to relax.  Almost every time I miss a passing shot or misplace a lob, it’s because I tensed up on the shot.  Forget about hittng the ‘big’ winner and just go for more winning shots in the first place.  You will win far more points, which could be the deciding factor in a close match.

Good luck with the game!

Categories: Tennis