08-09-2016 06:18 AM
Hello
Not yet installed v13 yet, am still on v12.2.1 so cannot open the file.
A picture of the frame and method might show what your current issue is instead.
JamesM
08-09-2016 08:20 AM
08-09-2016 08:26 AM
Hello.
Looking at it there is a few issues, first of which the equasions to caculate the x and y look the same. If you noticed in the previous code I gave in the second part a plus and minius was changed, this is as the distance from the center point is in the oppesit direction.
Secondly, your code to caculate the mid point only works for them at a set angle and not at any angle. I do say having a fixed center point is best, if not then you got to revers engineer the mid point from the other equasions by resolving them for midpointX and midpointY instead.
JamesM
08-09-2016 08:36 AM
08-09-2016 08:45 AM
Hello
Ok, scrap that working backwards kind of approach, you got so many unknows it cant be done really, so instead have worked from scratch from it. imagin the 2 lines forming a box using the middle of the line as a side and connecting the ends together, then draw a diagonal from one corner to the other and then get the middle of that diagonal and it will be your center point.
local MidPointX : real := (Conv_1.xPos + (Conv_2.xPos + Conv_2.Length * (1 / ScalingFactor) * cos((Conv_2.ObjectAngle / 180) * Pi))) / 2 ; local MidPointY : real := (Conv_1.yPos + (Conv_2.yPos + Conv_2.Length * (1 / ScalingFactor) * sin((Conv_2.ObjectAngle / 180) * Pi))) / 2 ;
Assuming your 2 lines are parallel then either end of the box will have the same distance as the middle of the box, so the following can be done for the distance.
local Distance : real := sqrt((Conv_1.xPos - Conv_2.xPos)*(Conv_1.xPos - Conv_2.xPos) + (Conv_1.yPos - Conv_2.yPos)*(Conv_1.yPos - Conv_2.yPos)) / 2 ;
Have tested this a little and it appears to work correctly from randomly moving the lines about.
I am going to warn you now though, if you do not return them to where they were when you reset the model (meaning storing the midpoints) then they will start to slowly (and randomly) shift across the screen due to the rounding error. The rounding error comes in from the fact that you can only have whole pixels but we are caculating in perfect values, so when it is moved it will place them close to where thye belong. As you run it again rounding error will happen and your midpoint might be different from last time.
JamesM
08-09-2016 10:46 AM