修改一个公式从围绕一个圆周计算到一个椭圆? [英] Modify a formula from calculating around a circle to around an oval?
问题描述
现在我试图找出如何修改这个公式来考虑椭圆或椭圆。我确实想到首先将组件绘制成圆形,然后在所有绘制后拉伸,但这不是一个干净的解决方案,因为我正在做的绘图已经是椭圆形的。 / p>
我需要为这个函数添加一个参数来告诉它的宽度/高度之间的比例,所以它知道如何偏离这一点。默认情况下,此参数应为1,表示Width = Height,表示无椭圆形图形或偏移量。但是假设我放2,这意味着宽度是高度的两倍,或1.5表示宽度是高度的1.5倍。
这是原来的功能: / p>
function NewPosition(Center:TPoint; Distance:Integer; Degrees:Single):TPoint;
var
Radians:Real;
begin
//将角度从度转换为弧度;减去135以使位置为0度
Radians:=(度数 - 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;
结束
这里是需要添加的参数:
$ b $函数NewPosition(Center:TPoint; Distance:Integer; Degrees:Single;
OvalOffset:Single = 1):TPoint;
var
Radians:Real;
begin
//将角度从度转换为弧度;减去135以使位置为0度
Radians:=(度数 - 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;
结束
定义:
- 中心=从(椭圆中心)计算的中心点
- 距离=距离中心距离任何方向有多远, li>
- 学位=从右上角开始的中心点多少度
- OvalOffset =宽度和高度之间的差异比率
将 OvalOffset
添加到结果中。 Y
公式...
Result.Y:= Trunc((Distance * Sin(Radians) +距离* Cos(Radians))/ OvalOffset)
+ Center.Y;
I have this formula in a function below. It's a fairly simple concept, yet this formula took me almost 2 weeks to get perfect. What it does is calculates what point to place an object at a given degree around and distance from a central point. It's useful for manually drawing circles, and also I primarily use it for a needle gauge component of mine. It calculates where to draw the needle.
Now I'm trying to figure out how to modify this formula to take ovals or ellipses into account. I did think of the idea of drawing a component a round shape first, and then stretching it after everything's drawn, but this is not a clean solution, as the drawing which I'm doing will already be in the shape of an oval.
I need to add just one parameter to this function to tell it the ratio between the width/height so it knows how to off-set this point. By default, this parameter should be 1, meaning Width=Height, meaning no ovalish drawing or offset. But suppose I put 2, which means width is twice the size of the height, or 1.5 would mean 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 it is with the added parameter 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 = Central point where to base calculations from (center of ellipse)
- Distance = How far from Center in any direction, regardless of Degrees
- Degrees = How many degrees around central point, starting from up-right
- OvalOffset = Ratio of difference between Width and Height
Add a division by OvalOffset
to just the Result.Y
formula...
Result.Y:= Trunc((Distance*Sin(Radians)+Distance*Cos(Radians))/OvalOffset)
+Center.Y;
这篇关于修改一个公式从围绕一个圆周计算到一个椭圆?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!