1. ## [Discussion] AutoCAD Curve geometry - Calculating an average slope

Registered forum members do not see this ad.

I'd like to take an AutoCAD curve (polyline) & calculate the aproximate overall average slope of it. Attached is my code so far which works

Code:
```(defun weightedAverageSlopeOfCurve (<obj>)

;Some function variables
(setq chainage 0.0 interval 0.1 tempList nil orig (list 0 0 0 ) maxIterations (fix 1e5) average 0.0)

(setq startChainage (vlax-curve-getDistAtParam <obj> (vlax-curve-getStartParam <obj>))
endChainage  (vlax-curve-getDistAtParam <obj> (vlax-curve-getEndParam <obj>))
)

;Define the length of the curve

(setq curveLength (-  endChainage startChainage  )
chainage  startChainage)

;Caclulate the number of iterations

(setq iterations (fix (/ curveLength interval)))

;;Take some loading off the CPU if too many iterations required. Revert to maxIterations
(if
(> iterations maxIterations)
(setq interval (/ curveLength maxIterations) iterations maxIterations)

)

(repeat iterations

(setq dy/dx (vlax-curve-getFirstDeriv <obj> (vlax-curve-getParamAtDist <obj> chainage))
slope (angle orig dy/dx))

(setq average (+ average (/ slope iterations)))

(setq chainage (+ chainage interval))

)
average
)```

Has anybody any thoughts on the methodology or suggestions for a different approach?

2. your question is to vauge what is an average slope ? post example

3. Originally Posted by BIGAL
your question is to vauge what is an average slope ? post example
Hi BIGAL,

Sorry for not getting back to this sooner. I'll try and be a little clearer, average slope probably was the wrong term to use.

Taking an AutoCAD curve, in this case a polyline, I am intereseted in determining the average vector travelled going from the start point to the end point of the polyine.

My original thinking was to break the curve down into a series of segments, calculate the slope at each segment & from that calculate an overall average slope / vector travelled

Regards

Jammie

4. Wont the average of a arc just be the tangential slope at the mid point ?

5. Or even the line joining the start point to the end point

However the vectors vary along the way, they start at the start point and they arrive at the endpoint.

6. Registered forum members do not see this ad.

@BIGAL I hadn't considered that. I'll have to do a bit of testing to see how if/how I can incorporate this.

@eldon That was my thinking with vectors varing along the length of the curve. Every segment of the curve has a weighting on the overall average of the curve.

Perhaps the following could work?

Code:
```1.    Determine the number of curve segements  			(n)
2.    Find the tangent @ each mid segment         		(m)
3.    Find length of that segment              			(l)
4.    Determine the magnitude of the vector (l*m) 		(s)
5.    Add all the results & divide by total length of curve```
Thanks for the help so far

Jammie

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts