i'm kinda stuck on a concept.
Basically,
i want to do this:
I am given a Xmin Ymin, Xmax Ymax, and 3 sets of Coords to make a triangle.
Sounds simple enough,
however, this triangle must fit into a Row x Column grid.
The X and Y limits and the coords can be float and/or negative.
I have attempted to solve the placements of the coordinates by applying the y = mx + b formula.
Since basically, i want to scale Xmin Ymin Xmax Ymax to Row and Column Scale.
Eg. Row = 7, Col = 11
Xmin = -1
Xmax = 1
Ymin = 0
Ymax = 1
if i have three coordinates
(-0.4, 0) (0.95, 1) (-1, 0.33)
you should get something like this:
Code:
(each - is a column, and each | is a row)
for floats:
row: 7
column: 11
xmin: -1
xmax: 1
ymin: 0
ymax: 1
coords1: (-0.4, 0)....1
coords2: (0.95, 1)....2
coords3: (-1, 0.33)...3
y range = 0 to 1
^----------- ^
6| |
5| 2 |
4| |
3| |
2| 3 |
1| |
0| 1 |
^-----------^
0123456789a
x range -1 to 1
where a = 10
My problem is now, how do i scale it accordingly?
the way i attempted it was,
i have a Xmin to Xmax of -1 to 1, on 11 columns.
Code:
1 |
0 |
-1|______
..1 to 11
so by using y = mx + b
b (intercept) = -1
m (gradient) = rise/run = 2/11
x = (y-b)/m
so by applying that formula,
i should be able to get the corresponding value in the 1 to 11 scale.
similarly for the scale of 1 to 7,
where m = 2/7
Doing paper calculations,
for the coords to new coords
coords1: (-0.4, 0) => (3.3, 0) supposed to be (3,0)
coords2: (0.95, 1) => (10.7, 7.7) supposed to be (8,5)
coords3: (-1, 0.33) => (0, 2.31) supposed to be (1,2)
the same is applied for :
row: 5
column: 7
xmin: 0
xmax: 12
ymin: 0
ymax: 12
coords1: (1, 2) =>(0.58, 0.8), supposed to be(1,1)
coords2: (6, 10) =>(3.5, 4.1), supposed to be(3,3)
coords3: (11, 2) => (6.41, 0.8), supposed to be(5,1)
Code:
for ints:
row: 5
column: 7
xmin: 0
xmax: 12
ymin: 0
ymax: 12
coords1: (1, 2)....1
coords2: (6, 10)...2
coords3: (11, 2)...3
^-------^
4| |
3| 2 |
2| |
1| 1 3 |
0| |
^-------^
0123456
the coords are not the same as it should be.
Help plz ><
edit:
bad code tag,