Clirex
|
  |
| Joined: 22 Jun 2012 |
| Total Posts: 2477 |
|
|
| 11 Feb 2016 03:52 PM |
local DistanceLeft = 0
while Distance > SegmentLength do
DistanceLeft = DistanceLeft + SegmentLength
Distance = Distance - SegmentLength
end |
|
|
| Report Abuse |
|
|
|
| 11 Feb 2016 03:52 PM |
| add numbers and yes it can |
|
|
| Report Abuse |
|
|
Clirex
|
  |
| Joined: 22 Jun 2012 |
| Total Posts: 2477 |
|
| |
|
Clirex
|
  |
| Joined: 22 Jun 2012 |
| Total Posts: 2477 |
|
|
| 11 Feb 2016 03:55 PM |
| distance is the only thing i need |
|
|
| Report Abuse |
|
|
|
| 11 Feb 2016 03:57 PM |
| add variables. each var has a certain #. |
|
|
| Report Abuse |
|
|
Clirex
|
  |
| Joined: 22 Jun 2012 |
| Total Posts: 2477 |
|
|
| 11 Feb 2016 03:58 PM |
what i mean is can you solve it for me because i dont know how
Distance = Distance > SegmentLength and |
|
|
| Report Abuse |
|
|
|
| 11 Feb 2016 04:01 PM |
| that would be an infinite loop, imposible. |
|
|
| Report Abuse |
|
|
Clirex
|
  |
| Joined: 22 Jun 2012 |
| Total Posts: 2477 |
|
|
| 11 Feb 2016 04:04 PM |
what on earth are you talking about
i want a formula (like a 1 line equation) to replace this loop |
|
|
| Report Abuse |
|
|
Clirex
|
  |
| Joined: 22 Jun 2012 |
| Total Posts: 2477 |
|
|
| 11 Feb 2016 04:07 PM |
| i guess a better word would be an algorithm |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
| |
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 11 Feb 2016 04:10 PM |
| What are you trying to do with this algorithm? |
|
|
| Report Abuse |
|
|
Clirex
|
  |
| Joined: 22 Jun 2012 |
| Total Posts: 2477 |
|
|
| 11 Feb 2016 04:10 PM |
well
i tried it on my own, not sure if it works or not but here it is:
Distance = Distance > SegmentLength and Distance - (SegmentLength/Distance * SegmentLength) or Distance
|
|
|
| Report Abuse |
|
|
Clirex
|
  |
| Joined: 22 Jun 2012 |
| Total Posts: 2477 |
|
|
| 11 Feb 2016 04:11 PM |
| @eLunate i want to avoid pointless loops |
|
|
| Report Abuse |
|
|
Clirex
|
  |
| Joined: 22 Jun 2012 |
| Total Posts: 2477 |
|
|
| 11 Feb 2016 04:12 PM |
| @TimeTicks make distance >= segment length by subtracting segment length until that is achieved. |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 11 Feb 2016 04:12 PM |
| It's fine because as that stands, that'll only run once. As soon as you remove SegmentLength from Distance, it's assured to be less than SegmentLength. |
|
|
| Report Abuse |
|
|
Clirex
|
  |
| Joined: 22 Jun 2012 |
| Total Posts: 2477 |
|
|
| 11 Feb 2016 04:14 PM |
| @eLunate i feel like there is a better way to go about it |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 11 Feb 2016 04:27 PM |
How about we do
local lim = Distance/SegmentLength DistanceLeft = math.floor(lim)*SegmentLength; Distance = Distance - math.ceil(lim)*SegmentLength |
|
|
| Report Abuse |
|
|
Clirex
|
  |
| Joined: 22 Jun 2012 |
| Total Posts: 2477 |
|
| |
|
Clirex
|
  |
| Joined: 22 Jun 2012 |
| Total Posts: 2477 |
|
|
| 11 Feb 2016 04:33 PM |
thanks for your contribution fixed:
local lim = Distance/SegmentLength local DistanceLeft = Distance > SegmentLength and math.floor(lim)*SegmentLength or 0 Distance = Distance > SegmentLength and Distance - math.ceil(lim)*SegmentLength or Distance |
|
|
| Report Abuse |
|
|
Craftero
|
  |
| Joined: 24 Jun 2011 |
| Total Posts: 1451 |
|
|
| 11 Feb 2016 04:52 PM |
I don't know if this will help, but I thought I'd throw the idea out there in case it does help you out after all.
There is such a thing as the algebraic distance formula (or b-formula as it is sometimes referred to as). It's easy enough to find on the internet, if you're interested in looking into it more. |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
| |
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 11 Feb 2016 05:28 PM |
| You know, my code does exactly what your original code does. And now you're telling me that my code is wrong and that your revised code is obviously right. |
|
|
| Report Abuse |
|
|
Clirex
|
  |
| Joined: 22 Jun 2012 |
| Total Posts: 2477 |
|
| |
|