Scaling node coordinates to a fixed graph size

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 reply · 2K views
mcnkevin
Messages
6
Reaction score
0
Hi, suppose i have various graphs which each have many nodes. In one graph the nodes x and y values may be within the range 0-1000, in another the x values may range from 100-500 and the y values from 300-800. Basically, the ranges always vary and there is no consistency.

I need a way to scale the values of the x and y coordinates such that they fit inside a fixed graph size (say 500 by 500) such that the graph retains in basic layout and relative distances between nodes.

Probably not that hard a question, i just can't figure it out :). Thx for any help.
 
Mathematics news on Phys.org
If your graph x and y range from 0 to A and you want it to fit inside 0 to B, multiply all coordinates by B/A.

For example, if you x and y coordinates are always between 0 and 1000 and you want it to fit inside 0 to 500 multiply all coordinates by 500/1000= 1/2. So, for example, the point (900,800) would change to (450, 400).