折线图优化

This commit is contained in:
monitor1394
2019-05-25 00:39:33 +08:00
parent 6f6c469059
commit cdfef09129
3 changed files with 4681 additions and 2339 deletions

View File

@@ -318,6 +318,18 @@ namespace XCharts
return GetBezierList2(sp, ep, segment, cp1, cp2);
}
public static Vector3[] GetBezierListVertical(Vector3 sp, Vector3 ep, float k = 2.0f)
{
Vector3 dir = (ep - sp).normalized;
float dist = Vector3.Distance(sp, ep);
Vector3 cp1 = sp + dist / k * dir * 1;
Vector3 cp2 = sp + dist / k * dir * (k - 1);
cp1.y = sp.y;
cp2.y = ep.y;
int segment = (int)(dist / 0.3f);
return GetBezierList2(sp, ep, segment, cp2, cp1);
}
public static List<Vector3> GetBezierList(Vector3 sp, Vector3 ep, int segment, Vector3 cp)
{
List<Vector3> list = new List<Vector3>();
@@ -463,7 +475,7 @@ namespace XCharts
if (mm > 10)
{
mm = bigger - bigger % (Mathf.Pow(10, n));
mm += max >0 ? Mathf.Pow(10, n) : -Mathf.Pow(10, n);
mm += max > 0 ? Mathf.Pow(10, n) : -Mathf.Pow(10, n);
}
if (max < 0) return (int)-mm;
else return (int)mm;
@@ -502,5 +514,79 @@ namespace XCharts
trigger.triggers.Clear();
trigger.triggers.Add(entry1);
}
//获取两直线交点
public static Vector3 GetIntersection(Vector3 lineAStart, Vector3 lineAEnd, Vector3 lineBStart, Vector3 lineBEnd)
{
float x1 = lineAStart.x, y1 = lineAStart.y;
float x2 = lineAEnd.x, y2 = lineAEnd.y;
float x3 = lineBStart.x, y3 = lineBStart.y;
float x4 = lineBEnd.x, y4 = lineBEnd.y;
//equations of the form x=c (two vertical lines)
if (x1 == x2 && x3 == x4 && x1 == x3)
{
return Vector3.zero;
}
//equations of the form y=c (two horizontal lines)
if (y1 == y2 && y3 == y4 && y1 == y3)
{
return Vector3.zero;
}
//equations of the form x=c (two vertical lines)
if (x1 == x2 && x3 == x4)
{
return Vector3.zero;
}
//equations of the form y=c (two horizontal lines)
if (y1 == y2 && y3 == y4)
{
return Vector3.zero;
}
float x, y;
if (x1 == x2)
{
float m2 = (y4 - y3) / (x4 - x3);
float c2 = -m2 * x3 + y3;
x = x1;
y = c2 + m2 * x1;
}
else if (x3 == x4)
{
float m1 = (y2 - y1) / (x2 - x1);
float c1 = -m1 * x1 + y1;
x = x3;
y = c1 + m1 * x3;
}
else
{
//compute slope of line 1 (m1) and c2
float m1 = (y2 - y1) / (x2 - x1);
float c1 = -m1 * x1 + y1;
//compute slope of line 2 (m2) and c2
float m2 = (y4 - y3) / (x4 - x3);
float c2 = -m2 * x3 + y3;
//solving equations (3) & (4) => x = (c1-c2)/(m2-m1)
//plugging x value in equation (4) => y = c2 + m2 * x
x = (c1 - c2) / (m2 - m1);
y = c2 + m2 * x;
}
if (IsInsideLine(lineAStart, lineAEnd, x, y) &&
IsInsideLine(lineBStart, lineBEnd, x, y))
{
return new Vector3(x, y, 0);
}
return Vector3.zero;
}
private static bool IsInsideLine(Vector3 start, Vector3 end, float x, float y)
{
return ((x >= start.x && x <= end.x)
|| (x >= end.x && x <= start.x))
&& ((y >= start.y && y <= end.y)
|| (y >= end.y && y <= start.y));
}
}
}