Quantcast
Channel: Questions in topic: "curved path"
Viewing all articles
Browse latest Browse all 116

How to calculate curvature of a path?

$
0
0
Hello, My question is a mathmetical question rather than unity, but while I am trying to calculate it in unity I think it is suitable to ask it in here. I am trying to calculate curvature of path that is drawed with mouse. At following picture you can see what is the aim of game. User have to draw a path that having optimal curvature. [Picture][1] And here is my code for calculating curvature. float calculateCurvature() { //Choose points according to curvatureDelta List choosenPoints = new List(); choosenPoints.Add(positions[0]); //Positions list contains each position that is recorded in update function for (int i = 1; i < positions.Count; i++) { //Curvature delta is minimum distance from previous point for acounting next point from positions list. With this condition if user doesn't move his mouse //those points are not accounted and doesn't affect mean. if (Vector2.Distance(positions[i], choosenPoints[choosenPoints.Count-1]) >= curvatureDelta) choosenPoints.Add(positions[i]); } //Create lines List lines = new List(); for(int i = 1; i < choosenPoints.Count; i++) { Vector2 line = choosenPoints[i] - choosenPoints[i - 1]; lines.Add(line); Debug.DrawLine(choosenPoints[i], choosenPoints[i - 1], Color.red, 1000000); } //Calculate angles List angles = new List(); for (int i = 1; i < lines.Count; i++) { float angle = 180 - Vector2.Angle(-lines[i - 1], lines[i]); angles.Add(angle); //Debug.Log(angle); } return getMeanofList(angles); } However my code doesn't give stable result. So I thought I should apply a solid mathematical formula. But while path is drawed by user is not a smooth path I am not sure curvature formula will work in my case. So I am looking a way to calculate curvature with a proper way. [1]: https://ibb.co/iKqM55

Viewing all articles
Browse latest Browse all 116

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>