Change the calculation formula in a circle around the oval?

I have this formula in the function below. This is a fairly simple concept, but this formula took me almost 2 weeks to achieve perfection. What he does is calculate which point to place the object to a predetermined degree around and the distance from the center point. This is useful for drawing circles by hand, and I primarily use it for the component of the needle meter. It calculates where to draw the needle.

Now I'm trying to figure out how to change this formula to account for ovals or ellipses. I thought about first drawing a component of a round shape, and then stretching it after everything drawn, but this is not a clean solution, since the drawing I am making will already be in the shape of an oval.

I need to add only one parameter to this function to talk about the relationship between width and height, so that he knows how to disable this point. By default, this parameter should be 1, that is, Width = Height, which means there is no oval drawing or offset. But suppose I put 2, which means that the width is twice the size of the height, or 1.5 means that the width is 1.5 times the height.

Here's the original function:

function NewPosition(Center: TPoint; Distance: Integer; Degrees: Single): TPoint; var Radians: Real; begin //Convert angle from degrees to radians; Subtract 135 to bring position to 0 Degrees Radians:= (Degrees - 135) * Pi / 180; Result.X:= Trunc(Distance*Cos(Radians)-Distance*Sin(Radians))+Center.X; Result.Y:= Trunc(Distance*Sin(Radians)+Distance*Cos(Radians))+Center.Y; end; 

Here with the parameter added, I need:

 function NewPosition(Center: TPoint; Distance: Integer; Degrees: Single; OvalOffset: Single = 1): TPoint; var Radians: Real; begin //Convert angle from degrees to radians; Subtract 135 to bring position to 0 Degrees Radians:= (Degrees - 135) * Pi / 180; Result.X:= Trunc(Distance*Cos(Radians)-Distance*Sin(Radians))+Center.X; Result.Y:= Trunc(Distance*Sin(Radians)+Distance*Cos(Radians))+Center.Y; end; 

DEFINITIONS:

  • Center = Center point, where the basic calculations from (the center of the ellipse)
  • Distance = how far from the center in any direction, regardless of degree.
  • Degrees = How many degrees around the center point, starting from the top level.
  • OvalOffset = ratio of the difference between width and height

enter image description here

+6
source share
1 answer

Add division by OvalOffset only to the formula Result.Y ...

 Result.Y:= Trunc((Distance*Sin(Radians)+Distance*Cos(Radians))/OvalOffset) +Center.Y; 
+6
source

Source: https://habr.com/ru/post/903387/


All Articles