B4J Tutorial [B4X] Measure Line Lengths and Intersection Angles - Draggable Points



This post is partly in response to

The attached project is a very short demo (300 lines of B4X code) of drawing sequences of lines and computing lengths and intersecting angles.
The units in the grid are abstract and can be any real world units.

I call it measure2X, since I learned early in my woodworking hobby to measure twice and cut once.
The various techniques in the code could be used anywhere you need them.

The code as a whole could also be useful in other situations.
For example given three sides of any triangle, what are the internal angles?
Or, given an angle between two line of a given length, how far apart are the bases of the lines?

It could also be the foundation of robotic movements - if line length constraints are applied when dragging points (not done).
I used crossplatform code, tested in B4J and B4A.

INSTRUCTIONS:
1. Click anywhere on outer panel to add a point - more than one point will result in a line with its length in units (center of line)
2. The X and Y of the point will be shown in blue - X is units from left of the grid, and Y is units from bottom of grid
3. When two or more lines are visible the smallest angle between (in degrees) will be shown in red below the intersection
4. Drag any point to see the changing numbers
5. The "X" above the grid clears the trail and starts with an empty grid
6. Mouse down and up without significant movement removes a point from the trail - confirmation asked - redo not implemented

Note: My desktop screen is fairly large - you may need to change the values below in Main
#Region Project Attributes
#MainFormWidth: 1600
#MainFormHeight: 1200
#End Region
 

Attachments

  • measure2X.zip
    17.9 KB · Views: 50
Last edited:

rabbitBUSH

Well-Known Member
Licensed User
Mmmmm In my past life working in an institution with academics (sorry an university) the first thing they gave me to do was to translate a piece of software from Apple II basic to non-Apple PC. the program was called liftRISK and was used in ergonomic research on humans lifting stuff (particular focus on loads and related back injuries resulting). The whole maths for that (and the linked in question you note) is in that C code. A colleague and I then went on to see if we could do that all in dynamic mode (liftRISK being in static positions). An interesting one -> how many joints are involved in lifting thingX - etc. etc. etc..

Gee if I only had to do that stuff now with B4X and this example.
 
Last edited:

William Lancee

Well-Known Member
Licensed User
Longtime User
@rabbitBUSH

Funny you should mention this example applied to human joints. My second job was working in a lab with an engineer. One of our projects was for an orthopedic surgeon who was responsible the performance of athletes training for the Olympics. It was so long ago, I didn't think of it until now.

He wanted a tool called a knee goniometer, which you can imagine is a brace around the knee with potentiometers at the hinges.
As the athlete wearing this would walk, a printer would chart the gait with three separate signals (up/down, side to side, and separation gap).
The engineer built the apparatus and I wrote the software for an early microprocessor. Fascinating times. Don't get me started
 

rabbitBUSH

Well-Known Member
Licensed User
Don't get me started
AH! The Good Old Goinometer -> [[ oops goniometer ]]

Some day i'll tell you about the :
metal walkway -> foot landing patterns with head-loading
treadmill -> poor fellows running up 17deg at full tilt sprint and [breathing capture (a freaking nightmare)]
the dunking tank
and what else from all those days ago . . . . .

most of all -> don't get me started on trying to get upper, lower and what do you expect parameters from academics!!!!

(incidentally, I just remembered -> the academic in mention worked in Canada for many years then came back here -> go figure why?) Not sure but he may have been at Simon Fraser.)


 

jroriz

Active Member
Licensed User
Longtime User
Wow!
This is exactly what I needed to get started!
Thank you very much!
As soon as I make progress, I will post it here on the forum.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…