I need to draw some vectors (defining different speeds in Km/h) inside a Canvas. If I use the speed value (module) of the vectors, their length exceeds the limits of the Canvas (width and height) so I need to scale them maintaining the relative proportions (i.e. if vector A is twice vector B, it must stay so in the drawing as well).
I really have no idea how to do it. I found a Xojo example (it is called Newton27, don’t remember where I got it) which scales vector but it is very difficult to follow the process because it jumps through different methods and properties.
I’m looking for something fairly simple, if someone has already tackled the same problem in his/her coding.
Would love to have a look at that. Can you set up a link?
No problem. It should be this link:
(if it does not work let me know, I’m no great Dropbox expert)
Well, if all you need to do is zoom in and out then simply replace each x and y with xZoomFactor and yZoomFactor respectively.
Look at the CanvasZoom example included with Xojo.
Maybe I was unclear: what I need to do is scaling whatever vector to fit the Canvas. I have to figure out the scaling factor.
I gather you succesfully downloaded Newton27?
You’ll need to iterate through all your vectors and find the largest X and Y values. Then your scale factors are
maxX / canvas.Width
maxY / canvas.Height
Note that this could distort your image. If that isn’t acceptable, then take the smaller scale factor (assuming they’re less than 1) and use that for both X and Y.