Draw lines and measure angles

Try this

drawLines.aia (3.9 KB)

The four balls are set to Origin at Centre
You can use the ball x and y positions for the calculations

Watch out for ball/sprite cannibalisn!
https://groups.google.com/d/msg/mitappinventortest/FuVKBNJwjfg/srrPgAmTCgAJ

Check out the pool cue code in this sample, for how to dynamically move and rotate a line with one end pinned to the Canvas ...

1 Like

This aia fixes the cannibalism

drawLines2.aia (4.8 KB)

1 Like

Awesome thanks, I've made good progress. Really appreciate the help.
Is there a way to zoom in on the canvas to make more precise adjustments to the ball positions?

See HERE
and
HERE

for some ideas....

A post was split to a new topic: I cannot get the Canvas to adjust to the aspect ratio of the Image Picker

Ok, I have got the canvas and balls to work, and set up a default layout.
Here is a diagram of lines and angles I require: Angles B-F

Here are the blocks I have, but doesnt work yet. Any ideas why?

Thanks,
Jakes

I haven't thought through the trigonometry on this, but at first glance it is necessary for your code to take into account the (x,y) values of three Balls:

  • shoulder
  • elbow
  • hand

That's 6 numbers.

I don't see you doing that.

1 Like

Correct @ ABG

Where is your "slope" calculation for BC ? (refer back to my first example)

Thanks for the feedback - I missed that. I have added the calculation for BC now, still no luck.
I see in your example you have used a list to get theX,Y points. In my example I tried to get them directly from the balls. Maybe its the issue here?

Assuming the cyclist doesn't scratch his nose or break his elbow,
the angle of his elbow B is going to be obtuse, the sum of 2 acute angles + 90 degrees.
This construction shows the two acute angles:


I added two necessary corner points to the diagram,
to give us 2 new X values and 2 new Y values for the arctan values you will need to add.

Heading clockwise around point B, here are the angles to add:

  • arctan((B.X-C.X)/(B.Y-C.Y))
  • 90 degrees
  • arctan((A.Y-B.Y)/(A.X-B.X))

based on the formula tan(acute angle) = opposite side length/adjacent side length

Please note that AI2 uses degrees, not radians.

Ok, Ive used formulas to calculate the angle of each segment, and then another formula to calculate the angle between the lines. Working fine, but the moment the angle go over 90 degrees, it shows wrong, For example it works fine from 180 degrees down to 90, but the moment I go less than 90, for example 60 deg, it shows 240.

I have tried something similar to this, as well:

Any idea what I can change?

Again, back in my first example, it output all three angles. Somehow, one has to figure out which angle is the correct one to apply, given it all depends on which way around you draw the lines, perhaps a user choice ?

The first section of your code computes some tangents, and drops them into variables with 2-letter names.

The special case you are complaining about might cause negative tangent values, which you can test for before deciding how to calculate your angles.

I am unfamiliar with the formula you use for calculating angles, with the "1 + tan()*tan()" denominator. Can you post a link to its derivation?

If your formula response is out of range but can be normalized, here are some normalization routines in this sample app:

The link is in post #2 of this topic

I see three Notes between the formula derivation and examples at

One of the notes warns against bad results if one of the lines is parallel to one of the axes.

For a really limber cyclist, I would fall back to a solution using the atan2 function, which is less susceptible to infinite slopes.

Thanks for all the usefull info. I will work through them and get to a solution :slight_smile:
Time to use more brain power

Is there a way to have two linetypes on a canvas. I see you can change the line weight colour ect, but that applies to all the lines. I need to have two line types.
Thanks

Just set the line width/colour for each line you draw...?

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.