How to cut corners?

Crunch crunch.

Using the calculations from Getting the endpoint in ArcSegment using Start X / Y and Start + Sweep Angles , how can I twist or inflate (-ify) angles.

See images below. The green box is original. The yellow lines show that there should be a start or inflate start / end angle, but the red line, if the initial start angle = 169, end = 293 is supported on crossed or inflated elliptical arcs.

I need a way to figure out how to create new start / end angles based on the original values ​​in the green field and the height / width / xRadius / yRadius values ​​in the blue and orange rectangles.

originalwidth-scrunchedheight-scrunched

Does anyone know the calculation to figure out what a new angle should be?

+6
geometry wpf drawing angle
source share
2 answers

I wrote a table to calculate this. You can see it https://skydrive.live.com/redir?resid=23B7BEDE6527529E!529&authkey=!AGboDW72AySsnK8 if you want. (This should result in an online version, but you can also download it.)

The basic technique works as follows:

  • Design X and Y coordinates for unused endpoints.
  • Configure them with simple scaling to get the X and Y coordinates for the desired endpoints.
  • Work with angles

This includes quite a few calculations. You can trace it in this table, but here are all the steps:

Firstly, I convert your angles to use the coordinates of the coordinate geometry - as far as I can tell, you measure clockwise from 3 o’clock, but in the coordinate geometry it is more normal for a positive angle to be counterclockwise. Thus, your starting and ending angles become respectively 191 and 67 degrees. (I did this because I think math is less confusing this way.))

The spreadsheet then processes the radius at the start and end points. Here are the formulas that I use for the start and end points:

=D2*D3/SQRT(POWER(D3*COS(RADIANS(D4)),2) + POWER(D2*SIN(RADIANS(D4)),2)) =D2*D3/SQRT(POWER(D3*COS(RADIANS(D5)),2) + POWER(D2*SIN(RADIANS(D5)),2)) 

D2 and D3 are the radius of X and Y. D4 is the starting angle, and D5 is the ending angle (corrected for the corners). I got this formula from the Wikipedia article in Ellipses in the section “Polar form relative to the center”. This equation takes an angle and tells you that the radius of the ellipse will be at that angle.

Next, I use this to calculate the X and Y coordinates for the start and end points. Here are the formulas for starting X and Y:

 =$B$8*COS(RADIANS(D4)) + D2 =D3-$B8*SIN(RADIANS(D4)) 

As mentioned earlier, D2 and D3 are the radius of X and Y, and D4 is the starting angle. (The formulas for the end of X and Y look the same only with D5. The reason for adding the radius X is that without these numbers from -Xradius to + Xradius. Adding this means they range from 0 to width. Something similar, but I turned it over to get the coordinates of the screen, because computer graphics systems often have it upside down (where the Y increase goes down the page). Yes, it didn’t quite follow that I turned it over, but adjusted the angle ..sorry!

Next, we calculate the smoothed X and Y. Here are the formulas for the starting point:

 =B9/B2*B13 =B10/B3*B14 

B9 and B10 are the preliminary stretch marks X and Y calculated in the previous step. B2 and B3 are the original width and height, while B13 and B14 are the smoothed width and height. (The end formulas look pretty similar, of course.) So, this is just a simple scaling operation.

Finally, calculate the angle from them. Here's the formula for the starting angle (and the ending angle is almost identical)

 =MOD(DEGREES(ATAN2(B16 - $D$13, $D$14-B17)), 360) 

The ATAN2 function takes the X and Y coordinates and indicates the angle of the line from the origin to the point X, Y. Excel works in radians, so we need to convert this back to degrees (just like in the previous formulas I converted degrees to radians). And then I take it MOD 360, so as not to get any negative angles. ATAN2 never produces values ​​in excess of PI (i.e., 180 degrees), and creates negative values ​​for angles that go beyond that. Taking this modulo 360, he returns it to a positive number.

And then the last step is to convert this back to your system with a clockwise angle:

 = 360 - B19 

Filing in stretched sizes 1.88 / 3.4, we get 165.51 and 287.70 degrees. This doesn't exactly match your numbers, but I'm trying to figure out where you got them from. Are they made by eye? And the food is at 2.5 / 2.55, I get 171.71 and 299.51. Again, it is very slightly different from yours, but not much.

+1
source share

If you think about what this code does, it is very similar to the vertical or horizontal scale (which, by the way, will work?). I think this gives us the key to solving this issue without going into the ellipse-specific geometry.

A general approach is to determine the end points in x, y coordinates based on the angle and radius settings, apply scale factors, and then convert back to angles. The first thing we need to know is the center of the ellipse. What we know is the start and end points, as well as the start and end angles. With this information we can create a really simple system of equations and solve: ((x, y) is the center of the ellipse)

(yEnd-y) / (xEnd-x) = tan (endAngle) = line slope from the center to the end point (yStart-y) / (xStart-x) = tan (startAngle) = line slope from the center to the end point

With this small amount of information, we can now calculate the new center (x ', y'), x and y radii, and the end point (xEnd ', yEnd') using scale factors. (I believe that the starting point by definition is 0.0, but change if necessary).

x '= x * xScale, y' = y * yScale xEnd '= xEnd * xScale, yEnd' = yEnd * yScale

xRadius '= xRadius * xScale, yRadius' = yRadius * yScale

Now we need to find out new angles.

Math.Atan2 (yStart ', xStart') = new starting angle Math.Atan2 (yEnd ', xEnd') = new starting angle

Does this strategy make sense?

0
source share

All Articles