Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to calculate points along a circle by angle in Autolisp?

12 REPLIES 12
SOLVED
Reply
Message 1 of 13
ShricharanaB
873 Views, 12 Replies

How to calculate points along a circle by angle in Autolisp?

Hi.

I have a block which is used to create turn sections.

 

 The block constitutes 20°/30°/45°/ of a turn. I want to calculate the point in which I need to add the next turn section. 

This is the block with 30° turn.

ShricharanaB_2-1672741430675.png

 

This is what I want to achieve.  

ShricharanaB_3-1672741455659.png

 

For this I need to calculate the points along that red center line intersecting at the given angle so I can add the next block.

 How can I calculate this? I assume I need Matrix calculation for this.

I have attached a sample drawing for this. I've already figured out how to add the block with the required rotation and at the location. 

Thanks in advance for any help. 

 

Labels (2)
12 REPLIES 12
Message 2 of 13
ВeekeeCZ
in reply to: ShricharanaB

Long time out of school huh? The math is not too complicated, you just need to stretch your brain a little bit. 

 

sin, cos... nothing?

 

 

 

Or... if that hurts too much, you can use POLAR func 

 

(defun c:endpoint ()

  (setq e (car (entsel)))
  (command "_point" "_non" (polar (getpropertyvalue e "Position")
				  (+ (getpropertyvalue e "Rotation") (/ pi 12))
				  (* (getpropertyvalue e "ScaleFactors/X") 264.1142))))

 

Message 3 of 13
ShricharanaB
in reply to: ВeekeeCZ

Hi, thanks for the function.
This is what I came up with while I waited for an answer.
(defun c:checking()
(setq p1 (getpoint "\nP1: ")
p2 (getpoint "\nP2: ")
radius (getreal "\nRadius: ")
ang (getreal "\nAngle: ")
)
(setq point3 (polar (polar p2 (angle p1 p2) (* radius (tan (dtr ang)))) (- (angle p2 p1) (dtr ang)) (- (/ radius (cos (dtr ang))) radius)))
(command "point" point3)
(princ)
)

 

Since p1 and p2 are already known in my main function which is a tangent to the circle at the insertion point, I'm using that here. Your way looks much simpler, will check it out. 

Message 4 of 13
ShricharanaB
in reply to: ВeekeeCZ

Hi,
The code works for the 30° block, but I'm trying to modify it to the 45° block and I'm having trouble understanding the last line of your code "(* (getpropertyvalue e "ScaleFactors/X") 264.1142)". Could you please explain?

This is the data I have while I calculate the the point to add the next block, angle, radius, p1 and p2.

ShricharanaB_0-1672749462940.png

I'm just realizing it would have been better if I added this information while I created the post. 

 

Message 5 of 13
ВeekeeCZ
in reply to: ShricharanaB

BeekeeCZ_0-1672750239722.png

 

Message 6 of 13
ShricharanaB
in reply to: ВeekeeCZ

Hi, 

 

Just understood what this line is "(* (getpropertyvalue e "ScaleFactors/X") 264.1142)".

I will have to keep measuring the distance from the insertion point to the end point and add it with conditions for every block with different radius and angle of turn to use the function you have written. Though it is clever, I  can't use it as I have to use the same function to add blocks which vary in both radius and turn angle.

Thank you for opening my perspective though, hadn't thought of getting the rotation from the entity itself. 

Message 7 of 13
ВeekeeCZ
in reply to: ShricharanaB


@ShricharanaB wrote:

... I will have to keep measuring the distance from the insertion point to the end point and add it with conditions for every block with different radius and angle of turn to use the function you have written. Though it is clever, I  can't use it as I have to use the same function to add blocks which vary in both radius and turn angle.

...


 

Well, do what you have to do... but I don't think it's necessary. 

Say, if every block contains a red arc, you can get the geometry you need from it. 

 

 

Message 8 of 13
ShricharanaB
in reply to: ВeekeeCZ

I will have to experiment with getting the geometry from the red arc. Though the similarities might end at the line color and it being an arc, of which there could be others in a block as well, not sure how to filter that. I will have to check if I can pass the start point to nentsel and return the arc entity.
Message 9 of 13
ВeekeeCZ
in reply to: ShricharanaB


@ShricharanaB wrote:
I will have to experiment with getting the geometry from the red arc. Though the similarities might end at the line color and it being an arc, of which there could be others in a block as well, not sure how to filter that.

 

Post some graphics or blocks to tet see what you have in mind.

 

 

 


@ShricharanaB wrote:
 I will have to check if I can pass the start point to nentsel and return the arc entity.

 

That's the NENTSELP. But don't use it, you gotta get that from a block definition - this story starts with (tblobjname "block" (cdr (assoc 2 (entget (car (entsel)))))) and the plot of the story lies just next to that (entnext that)

 

Message 10 of 13
dbroad
in reply to: ShricharanaB

Since roads don't always fit neatly into even angles, you should try creating dynamic blocks that allow for angle and radius flexibililty and for alignment.

Architect, Registered NC, VA, SC, & GA.
Message 11 of 13
Kent1Cooper
in reply to: ShricharanaB

If the Block names were not just [in the sample drawing] "30DEG Turn" and "45DEG Turn" but also included something by which you could know the radius [presumably at the center-line, since the insertion point is on that], this would be greatly simplified.  [Do you ever use such Blocks of more than one radius in the same drawing?  If so, surely Block names that refer only to the degrees of turn will conflict with each other.]

 

If the radius was extractable in some way from the Block name, the center of a Block's Arcs could then be derived from the insertion point and scale factors and rotation of the Block, and (polar) functions from there could pretty easily determine insertion points for next Blocks.

Kent Cooper, AIA
Message 12 of 13
Kent1Cooper
in reply to: Kent1Cooper

Another suggestion:  Make the insertion points of the Blocks the shared Arc center point.  Then a series of them, of the same radius and curving in the same direction, would all share the same insertion point, with only the rotation angles varying, and determining the rotation for the next one would be easy.

Kent Cooper, AIA
Message 13 of 13
ShricharanaB
in reply to: ShricharanaB

Hi,

 

Thank you all for the the suggestions.  At this point of time, editing the blocks is not in scope as they are already being used by others.

@dbroad These are not road blocks but conveyors so they will always have a preset angle defined by design. 

@Kent1Cooper 

1. Unfortunately The block names do not include any of this (angle, radius) instead they are created with an excel which does not take these things to account. The above names were just indicative not actual. For now I'm using condition to set the values of radius and turn angle since there are only few.

2. Since currently these blocks are being added manually and might be required in some cases in the future as well, the insertions are being done end to end so the arc center point cannot be the insertion point.

@ВeekeeCZ  I ended up using your polar method but with the length and the angle being calculated from the radius and the turn angle. Marking that as the answer. Thank you!

 

Here is the final code for polar I'm using where

p1, p2 - line tangent at point p2

turnSetAngle - angle of turn of the block in deg

curveSecRadius - radius of the block.

dtr - funciton to convert deg to rad. 

(polar p2 (+ (angle p1 p2) (* (dtr (/ turnSetAngle 2.0)) 2.0)) (* 2 curveSecRadius (sin (/ (dtr turnSetAngle) 2))))

 

Thanks again for taking the time to help me out!

Much appreciated!

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report