Notifications
Clear all

[Closed] Calculating pos to create points

You’ll see in the attached image what I’m after. Currently my script produces what is seen on the left side. The Larger crosshair points are in the correct places. However the smaller points are where I’m having problems. I want to place the smaller points from the center outward. The local rotation of the points themselves doesn’t matter, it’s more so the position that matters. The green shapes are just there to visually display the layout a little easier.

If this doesn’t make sense just let me know and I’ll try to better explain it.


delete objects

columns = 3
columnsRadius = (units.decodevalue "10cm")
strands = 1
strandsRadius = (units.decodevalue "5cm")
height = (units.decodevalue "0.0cm")

clearlistener()

columnAngle = 360.0 / columns as float
strandAngle = 360.0 / strands as float

for c = 1 to columns do
(
	col = random black white
	calcX = columnsRadius * cos((c-1) * columnAngle)
	calcY = columnsRadius * sin((c-1) * columnAngle)
	cornerPos = [calcX,calcY,height]
	
	/* Columns */
	point pos:cornerPos size:4 wirecolor:col
	
	/* Strands */
	for s = 1 to strands do
	(
		calcX = strandsRadius * cos((s-1) * strandAngle)
		calcY = strandsRadius * sin((s-1) * strandAngle)
		StrandPos = [calcX,calcY,height] + cornerPos
		
		point pos:StrandPos size:2 wirecolor:col
	)
)


22 Replies

On the right track…

Not sure where to place the offset variable


columnPos = [-5,5,0]
centerPos = [0,0,0]
offset = 2 --distance to offset smaller red point

v1 = normalize columnPos
v2 = normalize (centerPos - columnPos)
v3 = (dot v1 v2) * v2 - v1
offsetPos = columnPos + (v3 * (length v1)) 
	
point pos:columnPos size:3 wirecolor:yellow	
point pos:offsetPos size:2 wirecolor:red

are you not overcomplicating it John? surely you just need to normalize the column position vector and multiply it by the distance (plus an offset)

	delete objects

columns = 3
columnsRadius = (units.decodevalue "10cm")
strands = 1
strandsRadius = (units.decodevalue "5cm")
height = (units.decodevalue "0.0cm")

clearlistener()

columnAngle = 360.0 / columns as float
strandAngle = 360.0 / strands as float

centerPos = [0,0,0]

for c = 1 to columns do
(
	col = random black white
	calcX = columnsRadius * cos((c-1) * columnAngle)
	calcY = columnsRadius * sin((c-1) * columnAngle)
	cornerPos = [calcX,calcY,height]
	
	/* Columns */
	point pos:cornerPos size:4 wirecolor:col

	/* Strands */
	for s = 1 to strands do
	(
		nvec = (normalize cornerPos)	
		d = (distance centerPos cornerPos)		
		point pos:(nvec*(d*1.5)) size:2 wirecolor:col
	)
)


this yields the following :

awww nice.

I was over-complicating it way to much. I need to read up on my vectors again. When I’m away from them for awhile I tend to lose track of them. I appreciate your help and thank you very much for sharing your answer.

I see you are multiplying the d by 1.5.
How do you implement a specific offset such as 2 units rather than a percentage?


	/* Strands */
	for s = 1 to strands do
	(
		nvec = (normalize cornerPos)	
		d = (distance centerPos cornerPos)		
		point pos:(nvec*(d*1.5)) size:2 wirecolor:col
	)

I was just doing this… is this correct

d = (distance centerPos cornerPos) + 2

yes, that’s correct. You are multiplying a normalized vector, so the point will be located at the exact distance you specify from the origin, whether that is via a multiplier or an offset. If you made a point and gave it the nvec value as the position, it would be a point along that vector which is exactly 1 unit from the origin.

1 Reply
(@jokermartini)
Joined: 11 months ago

Posts: 0

I see. That is very cool and makes sense.
Thanks for explaining that to me.

I thought I would be able to simplify my problem and then apply it to what I as trying to do…seemingly that failed.

Here we are again back to step one. I want the white point to be the out most point from the center and the rest just go as follows in a circular patter.

The image on the left is what I get now. The image on the right is what I’ve after…


delete objects

columns = 4
columnsRadius = (units.decodevalue "12cm")
strands = 6
strandsRadius = (units.decodevalue "3cm")
height = (units.decodevalue "0.0cm")
centerPos = [0,0,0]

clearlistener()

columnAngle = 360.0 / columns as float
strandAngle = 360.0 / strands as float

for c = 1 to columns do
(
	calcX = columnsRadius * cos((c-1) * columnAngle)
	calcY = columnsRadius * sin((c-1) * columnAngle)
	cornerPos = [calcX,calcY,height]
	
	/* Columns */
	cPt = point pos:cornerPos size:4 wirecolor:yellow
	
	/* Strands */
	for s = 1 to strands do
	(		
		calcX = strandsRadius * cos((s-1) * strandAngle)
		calcY = strandsRadius * sin((s-1) * strandAngle)
		strandPos = [calcX,calcY,height]
		
		pt = point pos:strandPos size:2 wirecolor:[255/s,255/s,255]
		pt.pos += cPt.pos
	)
)

I wonder if there is a way that we could calculate some sort of rotation offset to just factor into the cos and sin


		calcX = strandsRadius * cos([U]45[/U]+(s-1) * strandAngle)
		calcY = strandsRadius * sin([U]45[/U]+(s-1) * strandAngle)

this does the tricks


delete objects

columns = 4
columnsRadius = (units.decodevalue "12cm")
strands = 6
strandsRadius = (units.decodevalue "3cm")
height = (units.decodevalue "0.0cm")
centerPos = [0,0,0]

clearlistener()

columnAngle = 360.0 / columns as float
strandAngle = 360.0 / strands as float

for c = 1 to columns do
(
	calcX = columnsRadius * cos((c-1) * columnAngle)
	calcY = columnsRadius * sin((c-1) * columnAngle)
	cornerPos = [calcX,calcY,height]
	
	/* Columns */
	cPt = point pos:cornerPos size:4 wirecolor:yellow
	
	/* Strands */
	for s = 1 to strands do
	(		
		calcX = strandsRadius * cos((columnAngle*(c-1))+(s-1) * strandAngle)
		calcY = strandsRadius * sin((columnAngle*(c-1))+(s-1) * strandAngle)
		
		--calcX = strandsRadius * cos((columnAngle*c)+(s-1) * strandAngle)
		--calcY = strandsRadius * sin((columnAngle*c)+(s-1) * strandAngle)
		strandPos = [calcX,calcY,height]
		
		pt = point pos:strandPos size:2 wirecolor:[255/s,255/s,255]
		pt.pos += cPt.pos
	)
)



2 Replies
(@denist)
Joined: 11 months ago

Posts: 0

i see that the math was not your favorite subject in the school… with the matrix algebra it solves by two lines of code.

(@gazybara)
Joined: 11 months ago

Posts: 0

Is this the solution that you have in mind


delete objects
 fn calcRadialPos num: idx: radius: high: tm:(matrix3 1) dis:#cw  =
 (
 	local ang = 360.0 / num, trg1, trg2
 	case dis of
 	(
 		(#cw): (trg1 = sin ; trg2 = cos)
 		(#ccw): (trg1 = cos ; trg2 = sin)
 	)
 	[(radius * trg1((idx-1) * ang)), (radius * trg2((idx-1) * ang)), high*(idx-1)] * tm
 )
 bigPointsCount = 8
 smallPointsCount = 12
 for b in 1 to bigPointsCount do
 (
 	bigPnt = point cross:off axistripod:on pos:(calcRadialPos num:bigPointsCount idx:b radius:50 high:0) size:5 wirecolor:yellow
 	for s in 1 to smallPointsCount do
 	(
 		smallPnt = point cross:off axistripod:on pos:(calcRadialPos num:smallPointsCount idx:s radius:10 high:3 tm:(bigPnt.transform) dis:#ccw) size:2 wirecolor:black
 	)
 )
 

here’s an extra snippet for you to mull over –

Since the cosine of an angle is the x projection on a circle with a radius of 1, and the sin the y projection, we can do this :


delete objects
dist = 10
mdist = 1 
for i = 45 to 360 by 45 do
(
	p = point pos:[cos i * dist, sin i * dist,0] size:2 wirecolor:(if mod i 90==0 then green else red)
	for i = 45 to 360 by 45 do	
			point pos:([cos i * mdist, sin i * mdist,0]+p.pos) size:0.5 wirecolor:(if mod i 90==0 then yellow else orange)
	
)

although in your case, the angle is 90 on the first loop

You’ve condensed the code quite a fair bit haha.
The thing to then add to this is to make the starting point for each sub array of points to be placed as the outter most point.

Page 1 / 2