In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces "how to use Unity to calculate the reversing track of the front and rear wheels of the car". In the daily operation, I believe that many people have doubts about how to use Unity to calculate the reversing track of the front and rear wheels of the car. The editor consulted all kinds of data and sorted out a simple and easy-to-use method of operation. I hope it will be helpful for everyone to answer the doubt of "how to use Unity to calculate the reversing track of the front and rear wheels of the car". Next, please follow the editor to study!
The calculation of the reversing track of the front and rear wheels is attached with C # source code (Unity) for your reference. The details are as follows.
The principle is very simple, it's all the geometry and mathematics part of high school.
The required parameters are:
Front and rear wheelbase
Car width (distance between left front wheel and right front wheel)
Current wheel angle (33.5 °for most cars)
Do you want to draw the front wheel track line?
/ get the track prediction index = 0 left track / steering wheel angle / front and rear wheelbase / / width / point density / whether it is the maximum turning angle / crossover array of the front wheel / / track, the subscript is 0 is the right line, and the table below is the left side line public Vector3 [] [] GetCarTrack (float steeringAngle, float carWheelbase, float carWidth, float length, bool isFront Float maxAngle = 90f) {float maxSteerAngle = _ carControl._vehicleController.steering.maxSteerAngle Float theta = Mathf.Abs (steeringAngle / 180 * Mathf.PI); Vector3 [] [] track = new Vector3 [2] []; List trackLeft = new List (); List trackRight = new List (); if (theta = = 0) {for (float I = 0; I)
< length; i++) { float x = i / length * 5; if (isFront) { x *= 1; trackLeft.Add(new Vector3(x, 0f, carWidth)); trackRight.Add(new Vector3(x, 0f, 0f)); } else { x *= -1; trackLeft.Add(new Vector3(x, 0, carWidth)); trackRight.Add(new Vector3(x, 0, 0)); } } } else { if (isFront) { float r = (carWheelbase / Mathf.Tan(theta) + carWidth / 2) / Mathf.Cos(theta); float rMin = Mathf.Cos(theta) * r - carWidth; float theta1 = Mathf.Atan(carWheelbase / rMin); rMin = rMin / Mathf.Cos(theta1); float rMax = rMin + carWidth; float lineAngle = carWheelbase / (rMax * 2f * Mathf.PI) * 360f; for (int i = 0; i = (maxAngle - lineAngle) / maxAngle) { float x = rMin * Mathf.Cos(maxAngle / length * i * Mathf.Deg2Rad); float z = rMin * Mathf.Sin(maxAngle / length * i * Mathf.Deg2Rad); if (x >= carWheelbase) {if (steeringAngle > 0) {trackRight.Add (new Vector3 (x-carWheelbase, 0, z-rMin + steeringAngle / maxSteerAngle * (carWidth / 2) } else {trackRight.Add (new Vector3 (x-carWheelbase, 0,-(z-rMin) + carWidth + steeringAngle / maxSteerAngle * (carWidth / 2) }} x = rMax * Mathf.Cos (maxAngle / length * I * Mathf.Deg2Rad); z = rMax * Mathf.Sin (maxAngle / length * I * Mathf.Deg2Rad) If (x > = carWheelbase) {if (steeringAngle > 0) {trackLeft.Add (new Vector3 (x-carWheelbase, 0, z-rMin + steeringAngle / maxSteerAngle * (carWidth / 2) } else {trackLeft.Add (new Vector3 (x-carWheelbase, 0,-(z-rMin) + carWidth + steeringAngle / maxSteerAngle * (carWidth / 2) } trackRight [trackRight.Count-1] = Vector3.forward * trackRight [trackRight.Count-1] .z; trackLeft [trackLeft.Count-1] = Vector3.forward * trackLeft [trackLeft.Count-1] .z } else {float r = (carWheelbase / Mathf.Tan (theta) + carWidth / 2) / Mathf.Cos (theta); float rMin = Mathf.Cos (theta) * r-carWidth; float rMax = rMin + carWidth Float lineAngle = carWheelbase / (rMin * 2f * Mathf.PI) * 360f; for (int I = 0; I = (maxAngle-lineAngle) / maxAngle) {float x =-rMin * Mathf.Cos (maxAngle / length * I * Mathf.Deg2Rad) Float z = rMin * Mathf.Sin (maxAngle / length * I * Mathf.Deg2Rad); if (steeringAngle > 0) {trackRight.Add (new Vector3 (x, 0, z-rMin)) } else {trackRight.Add (new Vector3 (x, 0,-(z-rMin) + carWidth)) } x =-rMax * Mathf.Cos (maxAngle / length * I * Mathf.Deg2Rad); z = rMax * Mathf.Sin (maxAngle / length * I * Mathf.Deg2Rad) If (steeringAngle > 0) {trackLeft.Add (new Vector3 (x, 0, z-rMin)) } else {trackLeft.Add (new Vector3 (x, 0,-(z-rMin) + carWidth)) } trackRight [trackRight.Count-1] = Vector3.forward * trackRight [trackRight.Count-1] .z; trackLeft [trackLeft.Count-1] = Vector3.forward * trackLeft [trackLeft.Count-1] .z }} track [0] = trackLeft.ToArray (); track [1] = trackRight.ToArray (); trackLeft = trackRight = null; return track;} at this point, the study on "how to use Unity to calculate the reversing track of the front and rear wheels of a car" is over, hoping to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.