Not exactly sure how to describe this but I need a formula I believe on how to plot a location of an obect and get it from point A to point B.
For example, I've got a black dot at 0,0...and I want to move him to 46,36 taking the most direct route (a line). If it were straight lines, it would be easy...but how do I do it with diagonals? I know there is some sort of formula for this used in games...I need it :)
The distance between points (x1,y1) and (x2,y2) is easily worked out
sqr((x1 - x2) ^ 2 + (y1 - y2) ^2 ) 'pythagoras
the angle to the horizontal is atn((y2 - y1) / (x2 - x1))
I'll try and explain my y = ax + b formula a bit more.
Given 'cartesian coordinates' that is with an x and y axis, you can express a formula for a straight line using the formula
y = ax + b
so for any x co-ordinate you can find the y co-ordinate which corresponds to the line.
In your case you have a line with b = 0 and a = 18/23
so at x = 46 you have y = 36
at x = 23 you have y = 18 so (23,18) is another point on your line.
I don't know if you'd want to use this in your program, one problem is that for a vertical line, a which is the gradient of your line becomes infinite. I just put it in as an afterthought in case it was what you were trying to work out.
Why wouldn't I want to use this? To me it looks like I can draw an imaginary line from point A to point B and have a dot travel the correct pixel path to those points, which is exactly what I need.
If what you say only works for diagonals, that's fine too because then for straight lines I simply check the previous X or Y and make sure one of those matches the new X or Y signifying a straight line. If not, then use the formula you posted. That sounds right don't ya think?
0
After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.
You guys must be mathimaticians :) Could you help out a mathimatically challenged soul by supplying a little example source :) nothing big, just something like here's point A, here's point B, and move a pixel along the path.
After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code.
This l…