Arc Direction

Arc Direction

Anonymous
Not applicable
1,066 Views
14 Replies
Message 1 of 15

Arc Direction

Anonymous
Not applicable
Hello
How can I know the direction of an arc (Clockwise and counter-clockwise) starting from a point S1, passing throught a point M1, and ending at a point E1, before drawing it?
thank you.
0 Likes
1,067 Views
14 Replies
Replies (14)
Message 2 of 15

Anonymous
Not applicable
[code]Function isLeft(LineStart, LineEnd, pt) As Integer
Dim Ans As Double
Ans = ((LineEnd(0) - LineStart(0)) * (pt(1) - LineStart(1)) _
- (pt(0) - LineStart(0)) * (LineEnd(1) - LineStart(1)))
Ans = Round(Ans, 12)
If Ans > 0 Then isLeft = 1: Exit Function 'Pt is left of the line (CW)
If Ans < 0 Then isLeft = -1: Exit Function 'Pt is right of the line (CCW)
If Ans = 0 Then isLeft = 0
End Function[/code]
0 Likes
Message 3 of 15

Anonymous
Not applicable
It works great, thanks a lot
0 Likes
Message 4 of 15

jbooth
Advocate
Advocate
If the arc is an existing entity (ie: an AcadArc object):

dim IsCCW as boolean
IsCCW = arc.EndAngle - arc.StartAngle >= 0

Note that 0-length arcs are (in the case above) considered as in a CCW direction.
0 Likes
Message 5 of 15

Anonymous
Not applicable
that's right, but I mentioned in my question that's using tree points, without any drawn arc.
0 Likes
Message 6 of 15

jbooth
Advocate
Advocate
So shoot me for giving you an *alternative solution, since according to your post you had plans to draw the arc regardless. 😉

Bryco's answer is correct, but it has extra calculations you don't need. (ex: rounding). I would personally modify it to the following:

Dim isCCW as Boolean
isCCW = ((M1(0) - S1(0)) * (E1(1) - S1(1)) - (E1(0) - S1(0)) * (M1(1) - S1(1))) > 0

Essentially, the z-value of the vector cross product (which is what you are calculating) will be greater than zero if the arc is CCW. Bryco was checking for < 0 because his vectors were in an order opposite to the above (still correct, just checking for something different).
0 Likes
Message 7 of 15

Anonymous
Not applicable
If you use doubles you need rounding.
0 Likes
Message 8 of 15

jbooth
Advocate
Advocate
Why? If VBA is that picky, change the > 0 to > 0#.

Am I missing something?
0 Likes
Message 9 of 15

Anonymous
Not applicable
Doubles require a bit of reading, the problem is a line on the x axis may report a y value however small. It's a universal problem, in net as well.
0 Likes
Message 10 of 15

jbooth
Advocate
Advocate
I doubt that is the case, but it shouldn't matter anyway. The resultant cross product of any two vectors is always orthoganal, regardless of their directions.

This means the result will be zero if and only if the arc's normal is parallel to the XY plane. Rounding will complicate things, as extremely small arcs will now round to zero instead of producing a directional result.
0 Likes
Message 11 of 15

Anonymous
Not applicable
I appreciate your response.
Because you look an expert mathematician, I would like to seize the opportunity to ask you about the 4x4 transformation matrix and what every item of it can be used for, the VBA help doesn't provide any deep clarification.
thanks in advance.
0 Likes
Message 12 of 15

Anonymous
Not applicable
Jason the formula I posted is all about the area of a triangle, I'm not too sure how the cross product fits in (It does look a little like a cross product. )
http://softsurfer.com/Archive/algorithm_0101/algorithm_0101.htm
0 Likes
Message 13 of 15

Anonymous
Not applicable
Saidab I understand very little math, but I have used matricies.
What are they, just a very good tool to figure out how to postion an object where you want to. They use 2 methods; translation (moving) and rotation (around the x,y and z axis).
A good introduction is to write your own rotation sub (e.g rotate a line about it's midpoint, not 0,0,0) , it's quite an eye opener.
0 Likes
Message 14 of 15

jbooth
Advocate
Advocate
Acutally, I'm just an engineering technologist. 😉

I've linked a decent example as to why you would need a 4x4 matrix here: http://en.wikipedia.org/wiki/Translation_matrix

Essentially what it's saying is that to transform a large number of 3D points, you can turn it into a Nx3 matrix and multiply it with a custom 3x3 matrix to get the result all at once.

Some transformations (ex: displacement) require a 4th set of points to define the custom transformation matrix. In other words, a 3D translation matrix is a 4x4 matrix. When this is the case, a 4th column is added to the source data so the multiplication is valid, and then ignored as a result after the multiplication is performed.

You can't multiply two matrices together unless the number of columns in the first matrix matches the number of rows in the second matrix. So you can't multiply a 2x3 with a 1x2, but you can multiply a 1x2 with a 2x3.

The 4th column can be used for other things, such as perspective projection, but I've already said too much.
0 Likes
Message 15 of 15

jbooth
Advocate
Advocate
Right.. I remember hearing that you can calculate the area of a triangle via the cross product of any two sides, but I've never personally tried it.
0 Likes