Need Start/End angles (orientation in space) from 3 coordinates

  • Thread starter Thread starter Darren J. Young
  • Start date Start date
D

Darren J. Young

Another math problem....

Given 3 points (X1,Y1)(X2,Y2)(X3,Y3) that define an arc (Start, Mid, and
End) I'm looking for a good formula that will return the start and end
angles. I'm not talking about the angles they form in relation to each
other, but the angles that represent their actual orientation in space.

I've got a whole ton of different arc formulas that I think I can work
into giving me what I want but I know it'll and up being 6 pages of
code. I know someone here would be better at producing a shorter more
efficient formula.

As my reward, here's my formula to give a radius based on an arc's chord
and it's sagitta length (line from mid point of chord to mid point of
arc) although I'd assume if you have the answer to my question, this
would have been a cake walk.

English version...
Radius = ((ChordLength / 2)^2 + SagittaLength^2) / (2 * SagittaLength)

Lisp version...
(/ (+ (expt (/ chord-length 2) 2) (expt sagitta-length 2))
(* sagitta-length 2.0)
)

--
Darren J. Young
CAD/CAM Systems Developer

Cold Spring Granite Company
202 South Third Avenue
Cold Spring, Minnesota 56320

Email: [email protected]
Phone: (320) 685-5045
Fax: (320) 685-5052
 
One way:

(defun seangles (p1 p2 p3)
(command "arc" p1 p2 p3)
(setq ent (entget (entlast)))
(entdel (entlast))
(list (cdr (assoc 50 ent))
(cdr (assoc 51 ent)))
)
 
Hi Darren , I check your formula but does not give the same result. Maybe I make a misstake.

As far as I know to have the center or the radious given the chord and saggita is a not so simple math fact.

But maybe you want to get such angles by LISP, if so the values can get by the lisp given at the other reply to your post.

Would you please explain what do you need or want to???

regards.
Devitg.
PS I will contact by your mail.
 
Since you've already determine the radius, which
is the core of the solution, the determination of the
start angles and endangles of the arc via calcs
(not by DXF) will turn out to be relatively easy.

Here's how I'll do it.

1). Determine the location of the center point of
the arc (mpt1=arc's midpoint; mpt2= chord's
midpoint and rad=calculated radius of arc):

(setq cpt (polar mpt1 (angle mpt1 mpt2) rad))

2). Determine start/end angle of arc:

(setq startang (angle cpt startpoint))

(setq endang (angle cpt endpoint))

All other details, I'll leave to your discretion.

HTH.

Leo
 
Heh, next time I'll read the request more carefully...... I saw "Given 3
points (X1,Y1)(X2,Y2)(X3,Y3) that define an arc" and I missed "(Start, Mid,
and End)"......

So here's what you need for obtaining the Radius, CenterPoint and Start &
End angles of an ARC through ANY 3 points..... ;-)

It's more code, but it will work regardless of the location on the arc of
Point2....where P1 = startpoint, P3 = endpoint.

I've been wanting to figure this out for some time and Darren gave me the
nudge to go ahead and research it...without even needing it.... ;-)

HTH,
Jeff

(defun rad3pts (p1 p2 p3 / A B C R q)
(setq A (distance p1 p2)
B (distance p2 p3)
C (distance p1 p3)
)
(setq q (/ (- (+ (expt A 2)(expt B 2)) (expt C 2)) (* 2 A B)))
(/ C (* 2 (sqrt (- 1 (expt q 2)))))
)

(defun radPnt (p1 p2 p3 R / halfchord l1 halfpt RP)
(setq halfchord (/ (distance p1 p3) 2)
l1 (sqrt (- (expt R 2) (expt halfchord 2)))
halfpt (polar p1 (angle p1 p3) halfchord)
)
(setq RP (polar halfpt (- (angle p1 p3) (/ pi 2)) l1))
(if (not (equal R (distance p2 RP) 0.0000001))
(setq RP (polar halfpt (+ (angle p1 p3) (/ pi 2)) l1))
)
RP
)

(defun get_angles (p1 p2 p3 / )
(setq R (rad3pts p1 p2 p3)
RP (radPnt p1 p2 p3 R)
startang (angle RP p1)
endang (angle RP p3)
)
)

EXAMPLE of how to use this data:
(get_angles p1 p2 p3)
(setq arc1 (vlax-invoke (get_space) "addarc" RP R startang endang))

(get_space) is another of my shortcut functions........
 
Hi Darren , I check your formula but does not give the same result. Maybe I make a misstake.

It works. Draw any arc. Draw in the Chord and Sagitta. Then post the
lengths of the chord and sagitta and what the radius is and I'll show
you the math with my formula.

Actually, it's not my formula, I mathematician gave it to me over ten
years ago.


--
Darren J. Young
CAD/CAM Systems Developer

Cold Spring Granite Company
202 South Third Avenue
Cold Spring, Minnesota 56320

Email: [email protected]
Phone: (320) 685-5045
Fax: (320) 685-5052
 
One way:
(defun seangles (p1 p2 p3)
(command "arc" p1 p2 p3)
(setq ent (entget (entlast)))
(entdel (entlast))
(list (cdr (assoc 50 ent))
(cdr (assoc 51 ent)))
)

Not feasible....I don't think at least, I'd have to benchmark it to be
certain. It would work, except that I would need to be doing this
possibly tens of thousands of times and it's my experience that (ENTMOD)
works quicker than (Command) and to use (entmod) I need the starting and
ending angles.


--
Darren J. Young
CAD/CAM Systems Developer

Cold Spring Granite Company
202 South Third Avenue
Cold Spring, Minnesota 56320

Email: [email protected]
Phone: (320) 685-5045
Fax: (320) 685-5052
 
Sorry, http://www.btlsp2000.com/CASO.LSP

Unless I'm misunderstanding something, this does (assuming you download
all the other support routines it needs) nothing but return the angle
the 2 lines make (and that's not always correct either) which is not
what I want.


--
Darren J. Young
CAD/CAM Systems Developer

Cold Spring Granite Company
202 South Third Avenue
Cold Spring, Minnesota 56320

Email: [email protected]
Phone: (320) 685-5045
Fax: (320) 685-5052
 
That'll work!

--
Darren J. Young
CAD/CAM Systems Developer

Cold Spring Granite Company
202 South Third Avenue
Cold Spring, Minnesota 56320

Email: [email protected]
Phone: (320) 685-5045
Fax: (320) 685-5052
 
Thanx Jeff. That's perfect. Exactly what I was looking for. Just wish I
understood the "math" of it all a little better.

--
Darren J. Young
CAD/CAM Systems Developer

Cold Spring Granite Company
202 South Third Avenue
Cold Spring, Minnesota 56320

Email: [email protected]
Phone: (320) 685-5045
Fax: (320) 685-5052
 
Posted to customer files. Given any three points, I want the start and
end angle of the arc those points define as they are related to the
arc's orientation in space (not the angle they form with each other).
can you provide with some "images" of what you are looking for?

PS: I've already got a solution better than what I was looking for
thanks to Jeff's code.

--
Darren J. Young
CAD/CAM Systems Developer

Cold Spring Granite Company
202 South Third Avenue
Cold Spring, Minnesota 56320

Email: [email protected]
Phone: (320) 685-5045
Fax: (320) 685-5052
 
Heh, next time I'll read the request more carefully...... I saw "Given 3
points (X1,Y1)(X2,Y2)(X3,Y3) that define an arc" and I missed "(Start, Mid,
and End)"......

This would make a good Lisp challenge.

Basically the same problem (find start/end angles in space) for the arc
they define given any three points.

But.....

Can not use Lisp functions like POLAR or draw anything and extract
coordinates. Solution must only use pure mathematical expressions using
the X/Y coordinates of the points, etc. Trig, Distances derived from
adding coordinates and dividing by 2, etc are all ok. I.e chord
length/1/2 length are ok because they can be calculated from the X/Y
coords. Angles must be calculated from trig functions, etc. Basically,
so the end formula could be plugged into any programming language or
calculator to come up with the result. ;-)

--
Darren J. Young
CAD/CAM Systems Developer

Cold Spring Granite Company
202 South Third Avenue
Cold Spring, Minnesota 56320

Email: [email protected]
Phone: (320) 685-5045
Fax: (320) 685-5052
 
Luis,
That works quite well!
I don't know why I forgot about the "inters" function.
I had thought about drawing construction lines to do this, but decided it
would be too slow. That's why I went with an all math solution.

Jeff
 
first it is what you want?
then the math stuff no problema Darren, ... my example was just a simple
one.

I've got what I need for this particular project but as I've looked at
the thread, I think about how it could be expanded a bit to be more
flexible.

Even Jeff's solution doesn't return the correct answer unless you pick
the start/end points in the proper order. I nice purely mathematical
solution where you could give any 3 points (2 would be endpoints) but in
any order, would be cool although it's way over my head.


--
Darren J. Young
CAD/CAM Systems Developer

Cold Spring Granite Company
202 South Third Avenue
Cold Spring, Minnesota 56320

Email: [email protected]
Phone: (320) 685-5045
Fax: (320) 685-5052
 
yes, i have done 18 arc draw solutions base on calcs... but is part of a
non-free app.

I certainly some expect you to give that away then. I've already got
what I want but watching the variety of solutions posted got me excited
about the different possibilities.

Your earlier INTERS solution was pretty sweet however. I might have to
use that it it's any more efficient than Jeff's see as this is going to
be performed repeatedly in the same routine.


--
Darren J. Young
CAD/CAM Systems Developer

Cold Spring Granite Company
202 South Third Avenue
Cold Spring, Minnesota 56320

Email: [email protected]
Phone: (320) 685-5045
Fax: (320) 685-5052
 
You didn't say it had to be fast - so this was only halfast, sorry.
 
Darren,
What you are looking at here is bulge factor.
The angle between the chord and a line that runs from the end of the arc to the end of the sagitta at the arc middle, is 1/4 of the included angle. You already have the way to figure the radius so then you can use the law of sines or the fact that any triangle = pi.

Bill

Bill
 
You didn't say it had to be fast - so this was only halfast, sorry.

Not a problem. It's been hectic and I didn't think out my post well
before I wrote it. I should have been more detailed in what I needed and
why.


--
Darren J. Young
CAD/CAM Systems Developer

Cold Spring Granite Company
202 South Third Avenue
Cold Spring, Minnesota 56320

Email: [email protected]
Phone: (320) 685-5045
Fax: (320) 685-5052
 
Back
Top