|
-
Oct 8th, 2015, 11:18 AM
#28
Re: Maths issue: coordinate systems
Okay, I couldn't let this puzzle get away from me.
You don't need any kind of library or code to solve simultaneous equations, since they are known, simply perform the calculations by hand to determine the formulae for each of the constants.
I came up with this code, which results in the same values using an online calculator.
Once the constants are known, you can type in any point, using the basic two equations, to get a point on the second chart:
Code:
Public Class Form1
Private P0 As PointF
Private P1 As PointF
Private P2 As PointF
Private Pa As PointF
Private Pb As PointF
Private Pc As PointF
Private N As Double
Private M As Double
Private C As Double
Private P As Double
Private Q As Double
Private D As Double
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'
' Set the CALIBRATION points
'
' Source points
Pa = New PointF(5, 1)
Pb = New PointF(2, 8)
Pc = New PointF(10, 7)
' Target Points
P0 = New PointF(2.1, 9.2)
P1 = New PointF(2.3, 1.6)
P2 = New PointF(9.1, 5.9)
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Call SolveConstants()
End Sub
Private Sub SolveConstants()
' M, N, C
' =======
' (1): P0x = M.Pax + N.Pay + C
' (2): P1x = M.Pbx + N.Pby + C
' (3): P2x = M.Pcx + N.Pcy + C
'
' Solving for N:
'
' (4): from (1): C = P0x - M.Pax - N.Pay
'
' from (2) and (4): P1x = M.Pbx + N.Pby + P0x - M.Pax - N.Pay
' = M.(Pbx - Pax) + N.(Pby - Pay) + P0x
' M.(Pbx - Pax) = P1x - N.(Pby - Pay) - P0x
' (6): M = (P1x - N.(Pby - Pay) - P0x) / (Pbx - Pax)
'
' using (4) and (3): P2x = M.Pcx + N.Pcy + P0x - M.Pax - N.Pay
' = M.(Pcx - Pax) + N.(Pcy - Pay) + P0x
' using (6): = (Pcx - Pax).(P1x - N.(Pby - Pay) - P0x) / (Pbx - Pax) + N.(Pcy - Pay) + P0x
' P2x.(Pbx - Pax) = (Pcx - Pax).(P1x - N.(Pby - Pay) - P0x) + N.(Pcy - Pay).(Pbx - Pax) + P0x.(Pbx - Pax)
' = P1x.(Pcx - Pax) - N.(Pby - Pay).(Pcx - Pax) - P0x.(Pcx - Pax) + N.(Pcy - Pay).(Pbx - Pax) + P0x.(Pbx - Pax)
' = P1x.(Pcx - Pax) + N.((Pcy - Pay).(Pbx - Pax) - (Pby - Pay).(Pcx - Pax)) - P0x.(Pcx - Pax) + P0x.(Pbx - Pax)
' (7): N = (P2x.(Pbx - Pax) - P1x.(Pcx - Pax) + P0x.(Pcx - Pax) - P0x.(Pbx - Pax)) / ((Pcy - Pay).(Pbx - Pax) - (Pby - Pay).(Pcx - Pax))
'
' Using (7)
N = (P2.X * (Pb.X - Pa.X) - P1.X * (Pc.X - Pa.X) + P0.X * (Pc.X - Pa.X) - P0.X * (Pb.X - Pa.X)) / ((Pc.Y - Pa.Y) * (Pb.X - Pa.X) - (Pb.Y - Pa.Y) * (Pc.X - Pa.X))
' using the results of (7) and putting in (6)
M = (P1.X - N * (Pb.Y - Pa.Y) - P0.X) / (Pb.X - Pa.X)
' Putting in (4):
C = P0.X - M * Pa.X - N * Pa.Y
Debug.WriteLine("N=" & N)
Debug.WriteLine("M=" & M)
Debug.WriteLine("C=" & C)
'
' Similarly for P, Q and D
Q = (P2.Y * (Pb.X - Pa.X) - P1.Y * (Pc.X - Pa.X) + P0.Y * (Pc.X - Pa.X) - P0.Y * (Pb.X - Pa.X)) / ((Pc.Y - Pa.Y) * (Pb.X - Pa.X) - (Pb.Y - Pa.Y) * (Pc.X - Pa.X))
P = (P1.Y - Q * (Pb.Y - Pa.Y) - P0.Y) / (Pb.X - Pa.X)
D = P0.Y - P * Pa.X - Q * Pa.Y
'
Debug.WriteLine("P=" & P)
Debug.WriteLine("Q=" & Q)
Debug.WriteLine("D=" & D)
'
End Sub
End Class
(Note that the code wraps ugly: the equations for N and Q are quite long, as well as the comments demonstrating how to solve for simultaneous equations).
"Ok, my response to that is pending a Google search" - Bucky Katt.
"There are two types of people in the world: Those who can extrapolate from incomplete data sets." - Unk.
"Before you can 'think outside the box' you need to understand where the box is."
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|